support systemd notifications

Fixes #1733
This commit is contained in:
Shivaram Lingamneni 2021-07-04 07:41:59 -04:00
parent c53df2dc88
commit 6f24082705
10 changed files with 123 additions and 2 deletions

View File

@ -8,13 +8,14 @@ After=network.target
# After=network.target mysql.service
[Service]
Type=simple
Type=notify
User=ergo
WorkingDirectory=/home/ergo
ExecStart=/home/ergo/ergo run --conf /home/ergo/ircd.yaml
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
LimitNOFILE=1048576
NotifyAccess=main
# Uncomment this for a hidden service:
# PrivateNetwork=true

1
go.mod
View File

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

2
go.sum
View File

@ -58,6 +58,8 @@ github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef h1:07e6GcSuNh1BoZJ
github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd h1:+iAPaTbi1gZpcpDwe/BW1fx7Xoesv69hLNGPheoyhBs=
github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd/go.mod h1:4soZNh0zW0LtYGdQ416i0jO0EIqMGcbtaspRS4BDvRQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=

View File

@ -21,6 +21,7 @@ import (
"unsafe"
"github.com/ergochat/irc-go/ircfmt"
"github.com/okzk/sdnotify"
"github.com/ergochat/ergo/irc/caps"
"github.com/ergochat/ergo/irc/connection_limits"
@ -124,6 +125,8 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
// Shutdown shuts down the server.
func (server *Server) Shutdown() {
sdnotify.Stopping()
//TODO(dan): Make sure we disallow new nicks
for _, client := range server.clients.AllClients() {
client.Notice("Server is shutting down")
@ -528,6 +531,8 @@ func (server *Server) rehash() error {
server.rehashMutex.Lock()
defer server.rehashMutex.Unlock()
sdnotify.Reloading()
config, err := LoadConfig(server.configFilename)
if err != nil {
server.logger.Error("server", "failed to load config file", err.Error())
@ -709,13 +714,15 @@ func (server *Server) applyConfig(config *Config) (err error) {
server.logger.Info("server", "Proxied IPs will be accepted from", strings.Join(config.Server.ProxyAllowedFrom, ", "))
}
// we are now open for business
err = server.setupListeners(config)
// send other config warnings
if config.Accounts.RequireSasl.Enabled && config.Accounts.Registration.Enabled {
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.")
}
// we are now open for business
sdnotify.Ready()
if !initial {
// push new info to all of our clients
for _, sClient := range server.clients.AllClients() {

21
vendor/github.com/okzk/sdnotify/LICENSE generated vendored Normal file
View File

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

15
vendor/github.com/okzk/sdnotify/README.md generated vendored Normal file
View File

@ -0,0 +1,15 @@
# sdnotify
sd_notify utility for golang.
## Installation
go get github.com/okzk/sdnotify
## Example
see [sample/main.go](sample/main.go)
## License
MIT

9
vendor/github.com/okzk/sdnotify/notify.go generated vendored Normal file
View File

@ -0,0 +1,9 @@
// +build !linux
package sdnotify
// SdNotify sends a specified string to the systemd notification socket.
func SdNotify(state string) error {
// do nothing
return nil
}

23
vendor/github.com/okzk/sdnotify/notify_linux.go generated vendored Normal file
View File

@ -0,0 +1,23 @@
package sdnotify
import (
"net"
"os"
)
// SdNotify sends a specified string to the systemd notification socket.
func SdNotify(state string) error {
name := os.Getenv("NOTIFY_SOCKET")
if name == "" {
return ErrSdNotifyNoSocket
}
conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: name, Net: "unixgram"})
if err != nil {
return err
}
defer conn.Close()
_, err = conn.Write([]byte(state))
return err
}

39
vendor/github.com/okzk/sdnotify/util.go generated vendored Normal file
View File

@ -0,0 +1,39 @@
package sdnotify
import (
"errors"
"fmt"
)
// ErrSdNotifyNoSocket is the error returned when the NOTIFY_SOCKET does not exist.
var ErrSdNotifyNoSocket = errors.New("No socket")
// Ready sends READY=1 to the systemd notify socket.
func Ready() error {
return SdNotify("READY=1")
}
// Stopping sends STOPPING=1 to the systemd notify socket.
func Stopping() error {
return SdNotify("STOPPING=1")
}
// Reloading sends RELOADING=1 to the systemd notify socket.
func Reloading() error {
return SdNotify("RELOADING=1")
}
// Errno sends ERRNO=? to the systemd notify socket.
func Errno(errno int) error {
return SdNotify(fmt.Sprintf("ERRNO=%d", errno))
}
// Status sends STATUS=? to the systemd notify socket.
func Status(status string) error {
return SdNotify("STATUS=" + status)
}
// Watchdog sends WATCHDOG=1 to the systemd notify socket.
func Watchdog() error {
return SdNotify("WATCHDOG=1")
}

3
vendor/modules.txt vendored
View File

@ -35,6 +35,9 @@ github.com/go-sql-driver/mysql
github.com/gorilla/websocket
# github.com/goshuirc/irc-go v0.0.0-20210318074529-bdc2c2cd2fef
## explicit
# github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd
## explicit
github.com/okzk/sdnotify
# github.com/onsi/ginkgo v1.12.0
## explicit
# github.com/onsi/gomega v1.9.0