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

+ 1
- 0
go.mod View File

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

+ 2
- 0
go.sum View File

@@ -58,6 +58,8 @@ github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef h1:07e6GcSuNh1BoZJ
58 58
 github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug=
59 59
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
60 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 63
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
62 64
 github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
63 65
 github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=

+ 8
- 1
irc/server.go View File

@@ -21,6 +21,7 @@ import (
21 21
 	"unsafe"
22 22
 
23 23
 	"github.com/ergochat/irc-go/ircfmt"
24
+	"github.com/okzk/sdnotify"
24 25
 
25 26
 	"github.com/ergochat/ergo/irc/caps"
26 27
 	"github.com/ergochat/ergo/irc/connection_limits"
@@ -124,6 +125,8 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
124 125
 
125 126
 // Shutdown shuts down the server.
126 127
 func (server *Server) Shutdown() {
128
+	sdnotify.Stopping()
129
+
127 130
 	//TODO(dan): Make sure we disallow new nicks
128 131
 	for _, client := range server.clients.AllClients() {
129 132
 		client.Notice("Server is shutting down")
@@ -528,6 +531,8 @@ func (server *Server) rehash() error {
528 531
 	server.rehashMutex.Lock()
529 532
 	defer server.rehashMutex.Unlock()
530 533
 
534
+	sdnotify.Reloading()
535
+
531 536
 	config, err := LoadConfig(server.configFilename)
532 537
 	if err != nil {
533 538
 		server.logger.Error("server", "failed to load config file", err.Error())
@@ -709,13 +714,15 @@ func (server *Server) applyConfig(config *Config) (err error) {
709 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 717
 	err = server.setupListeners(config)
714 718
 	// send other config warnings
715 719
 	if config.Accounts.RequireSasl.Enabled && config.Accounts.Registration.Enabled {
716 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 726
 	if !initial {
720 727
 		// push new info to all of our clients
721 728
 		for _, sClient := range server.clients.AllClients() {

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

@@ -0,0 +1,21 @@
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

@@ -0,0 +1,15 @@
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

@@ -0,0 +1,9 @@
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

@@ -0,0 +1,23 @@
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

@@ -0,0 +1,39 @@
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,6 +35,9 @@ github.com/go-sql-driver/mysql
35 35
 github.com/gorilla/websocket
36 36
 # github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef
37 37
 ## explicit
38
+# github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd
39
+## explicit
40
+github.com/okzk/sdnotify
38 41
 # github.com/onsi/ginkgo v1.12.0
39 42
 ## explicit
40 43
 # github.com/onsi/gomega v1.9.0

Loading…
Cancel
Save