Browse Source

support systemd notifications

Fixes #1733
tags/v2.8.0-rc1
Shivaram Lingamneni 2 years ago
parent
commit
6f24082705

+ 2
- 1
distrib/systemd/ergo.service View File

8
 # After=network.target mysql.service
8
 # After=network.target mysql.service
9
 
9
 
10
 [Service]
10
 [Service]
11
-Type=simple
11
+Type=notify
12
 User=ergo
12
 User=ergo
13
 WorkingDirectory=/home/ergo
13
 WorkingDirectory=/home/ergo
14
 ExecStart=/home/ergo/ergo run --conf /home/ergo/ircd.yaml
14
 ExecStart=/home/ergo/ergo run --conf /home/ergo/ircd.yaml
15
 ExecReload=/bin/kill -HUP $MAINPID
15
 ExecReload=/bin/kill -HUP $MAINPID
16
 Restart=on-failure
16
 Restart=on-failure
17
 LimitNOFILE=1048576
17
 LimitNOFILE=1048576
18
+NotifyAccess=main
18
 # Uncomment this for a hidden service:
19
 # Uncomment this for a hidden service:
19
 # PrivateNetwork=true
20
 # PrivateNetwork=true
20
 
21
 

+ 1
- 0
go.mod View File

14
 	github.com/go-test/deep v1.0.6 // indirect
14
 	github.com/go-test/deep v1.0.6 // indirect
15
 	github.com/gorilla/websocket v1.4.2
15
 	github.com/gorilla/websocket v1.4.2
16
 	github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef // indirect
16
 	github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef // indirect
17
+	github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd
17
 	github.com/onsi/ginkgo v1.12.0 // indirect
18
 	github.com/onsi/ginkgo v1.12.0 // indirect
18
 	github.com/onsi/gomega v1.9.0 // indirect
19
 	github.com/onsi/gomega v1.9.0 // indirect
19
 	github.com/oragono/confusables v0.0.0-20201108231250-4ab98ab61fb1 // indirect
20
 	github.com/oragono/confusables v0.0.0-20201108231250-4ab98ab61fb1 // indirect

+ 2
- 0
go.sum View File

58
 github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug=
58
 github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug=
59
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
59
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
60
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
60
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
61
+github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd h1:+iAPaTbi1gZpcpDwe/BW1fx7Xoesv69hLNGPheoyhBs=
62
+github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd/go.mod h1:4soZNh0zW0LtYGdQ416i0jO0EIqMGcbtaspRS4BDvRQ=
61
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
63
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
62
 github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
64
 github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
63
 github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
65
 github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=

+ 8
- 1
irc/server.go View File

21
 	"unsafe"
21
 	"unsafe"
22
 
22
 
23
 	"github.com/ergochat/irc-go/ircfmt"
23
 	"github.com/ergochat/irc-go/ircfmt"
24
+	"github.com/okzk/sdnotify"
24
 
25
 
25
 	"github.com/ergochat/ergo/irc/caps"
26
 	"github.com/ergochat/ergo/irc/caps"
26
 	"github.com/ergochat/ergo/irc/connection_limits"
27
 	"github.com/ergochat/ergo/irc/connection_limits"
124
 
125
 
125
 // Shutdown shuts down the server.
126
 // Shutdown shuts down the server.
126
 func (server *Server) Shutdown() {
127
 func (server *Server) Shutdown() {
128
+	sdnotify.Stopping()
129
+
127
 	//TODO(dan): Make sure we disallow new nicks
130
 	//TODO(dan): Make sure we disallow new nicks
128
 	for _, client := range server.clients.AllClients() {
131
 	for _, client := range server.clients.AllClients() {
129
 		client.Notice("Server is shutting down")
132
 		client.Notice("Server is shutting down")
528
 	server.rehashMutex.Lock()
531
 	server.rehashMutex.Lock()
529
 	defer server.rehashMutex.Unlock()
532
 	defer server.rehashMutex.Unlock()
530
 
533
 
534
+	sdnotify.Reloading()
535
+
531
 	config, err := LoadConfig(server.configFilename)
536
 	config, err := LoadConfig(server.configFilename)
532
 	if err != nil {
537
 	if err != nil {
533
 		server.logger.Error("server", "failed to load config file", err.Error())
538
 		server.logger.Error("server", "failed to load config file", err.Error())
709
 		server.logger.Info("server", "Proxied IPs will be accepted from", strings.Join(config.Server.ProxyAllowedFrom, ", "))
714
 		server.logger.Info("server", "Proxied IPs will be accepted from", strings.Join(config.Server.ProxyAllowedFrom, ", "))
710
 	}
715
 	}
711
 
716
 
712
-	// we are now open for business
713
 	err = server.setupListeners(config)
717
 	err = server.setupListeners(config)
714
 	// send other config warnings
718
 	// send other config warnings
715
 	if config.Accounts.RequireSasl.Enabled && config.Accounts.Registration.Enabled {
719
 	if config.Accounts.RequireSasl.Enabled && config.Accounts.Registration.Enabled {
716
 		server.logger.Warning("server", "Warning: although require-sasl is enabled, users can still register accounts. If your server is not intended to be public, you must set accounts.registration.enabled to false.")
720
 		server.logger.Warning("server", "Warning: although require-sasl is enabled, users can still register accounts. If your server is not intended to be public, you must set accounts.registration.enabled to false.")
717
 	}
721
 	}
718
 
722
 
723
+	// we are now open for business
724
+	sdnotify.Ready()
725
+
719
 	if !initial {
726
 	if !initial {
720
 		// push new info to all of our clients
727
 		// push new info to all of our clients
721
 		for _, sClient := range server.clients.AllClients() {
728
 		for _, sClient := range server.clients.AllClients() {

+ 21
- 0
vendor/github.com/okzk/sdnotify/LICENSE View File

1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2016 okzk
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.

+ 15
- 0
vendor/github.com/okzk/sdnotify/README.md View File

1
+# sdnotify
2
+
3
+sd_notify utility for golang.
4
+
5
+## Installation
6
+
7
+    go get github.com/okzk/sdnotify
8
+
9
+## Example
10
+
11
+see [sample/main.go](sample/main.go)
12
+
13
+## License
14
+
15
+MIT

+ 9
- 0
vendor/github.com/okzk/sdnotify/notify.go View File

1
+// +build !linux
2
+
3
+package sdnotify
4
+
5
+// SdNotify sends a specified string to the systemd notification socket.
6
+func SdNotify(state string) error {
7
+	// do nothing
8
+	return nil
9
+}

+ 23
- 0
vendor/github.com/okzk/sdnotify/notify_linux.go View File

1
+package sdnotify
2
+
3
+import (
4
+	"net"
5
+	"os"
6
+)
7
+
8
+// SdNotify sends a specified string to the systemd notification socket.
9
+func SdNotify(state string) error {
10
+	name := os.Getenv("NOTIFY_SOCKET")
11
+	if name == "" {
12
+		return ErrSdNotifyNoSocket
13
+	}
14
+
15
+	conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: name, Net: "unixgram"})
16
+	if err != nil {
17
+		return err
18
+	}
19
+	defer conn.Close()
20
+
21
+	_, err = conn.Write([]byte(state))
22
+	return err
23
+}

+ 39
- 0
vendor/github.com/okzk/sdnotify/util.go View File

1
+package sdnotify
2
+
3
+import (
4
+	"errors"
5
+	"fmt"
6
+)
7
+
8
+// ErrSdNotifyNoSocket is the error returned when the NOTIFY_SOCKET does not exist.
9
+var ErrSdNotifyNoSocket = errors.New("No socket")
10
+
11
+// Ready sends READY=1 to the systemd notify socket.
12
+func Ready() error {
13
+	return SdNotify("READY=1")
14
+}
15
+
16
+// Stopping sends STOPPING=1 to the systemd notify socket.
17
+func Stopping() error {
18
+	return SdNotify("STOPPING=1")
19
+}
20
+
21
+// Reloading sends RELOADING=1 to the systemd notify socket.
22
+func Reloading() error {
23
+	return SdNotify("RELOADING=1")
24
+}
25
+
26
+// Errno sends ERRNO=? to the systemd notify socket.
27
+func Errno(errno int) error {
28
+	return SdNotify(fmt.Sprintf("ERRNO=%d", errno))
29
+}
30
+
31
+// Status sends STATUS=? to the systemd notify socket.
32
+func Status(status string) error {
33
+	return SdNotify("STATUS=" + status)
34
+}
35
+
36
+// Watchdog sends WATCHDOG=1 to the systemd notify socket.
37
+func Watchdog() error {
38
+	return SdNotify("WATCHDOG=1")
39
+}

+ 3
- 0
vendor/modules.txt View File

35
 github.com/gorilla/websocket
35
 github.com/gorilla/websocket
36
 # github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef
36
 # github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef
37
 ## explicit
37
 ## explicit
38
+# github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd
39
+## explicit
40
+github.com/okzk/sdnotify
38
 # github.com/onsi/ginkgo v1.12.0
41
 # github.com/onsi/ginkgo v1.12.0
39
 ## explicit
42
 ## explicit
40
 # github.com/onsi/gomega v1.9.0
43
 # github.com/onsi/gomega v1.9.0

Loading…
Cancel
Save