Support systemd notify protocol (#17062)

This commit is contained in:
WGH 2023-05-02 09:15:08 +03:00 committed by GitHub
parent e8c0a50862
commit ab34f0065c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View file

@ -34,6 +34,7 @@ import (
"syscall"
"time"
"github.com/coreos/go-systemd/v22/daemon"
"github.com/minio/cli"
"github.com/minio/madmin-go/v2"
"github.com/minio/minio-go/v7"
@ -641,7 +642,10 @@ func serverMain(ctx *cli.Context) {
setConsoleSrv(srv)
go func() {
logger.FatalIf(newConsoleServerFn().Serve(), "Unable to initialize console server")
server := newConsoleServerFn()
logger.FatalIf(server.Listen(), "Unable to initialize console server's sockets")
daemon.SdNotify(false, daemon.SdNotifyReady)
logger.FatalIf(server.Serve(), "Unable to initialize console server")
}()
}

View file

@ -24,6 +24,7 @@ import (
"os"
"strings"
"github.com/coreos/go-systemd/v22/daemon"
"github.com/minio/minio/internal/logger"
)
@ -80,17 +81,23 @@ func handleSignals() {
exit(stopProcess())
case osSignal := <-globalOSSignalCh:
logger.Info("Exiting on signal: %s", strings.ToUpper(osSignal.String()))
daemon.SdNotify(false, daemon.SdNotifyStopping)
exit(stopProcess())
case signal := <-globalServiceSignalCh:
switch signal {
case serviceRestart:
logger.Info("Restarting on service signal")
daemon.SdNotify(false, daemon.SdNotifyReloading)
stop := stopProcess()
rerr := restartProcess()
if rerr == nil {
daemon.SdNotify(false, daemon.SdNotifyReady)
}
logger.LogIf(context.Background(), rerr)
exit(stop && rerr == nil)
case serviceStop:
logger.Info("Stopping on service signal")
daemon.SdNotify(false, daemon.SdNotifyStopping)
exit(stopProcess())
}
}

2
go.mod
View file

@ -14,6 +14,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coredns/coredns v1.10.1
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/coreos/go-systemd/v22 v22.5.0
github.com/cosnicolaou/pbzip2 v1.0.1
github.com/dchest/siphash v1.2.3
github.com/djherbis/atime v1.1.0
@ -112,7 +113,6 @@ require (
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/docker/go-units v0.5.0 // indirect