From b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:36:04 +0200 Subject: Adding upstream version 1.1.0. Signed-off-by: Daniel Baumann --- .../sample/main.go | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/main.go (limited to 'dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/main.go') diff --git a/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/main.go b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/main.go new file mode 100644 index 0000000..dd9d49e --- /dev/null +++ b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/main.go @@ -0,0 +1,57 @@ +package main + +import ( + "log" + "os" + "os/signal" + "syscall" + "time" + + "github.com/okzk/sdnotify" +) + +func reload() { + // Tells the service manager that the service is reloading its configuration. + sdnotify.Reloading() + + log.Println("reloading...") + time.Sleep(time.Second) + log.Println("reloaded.") + + // The service must also send a "READY" notification when it completed reloading its configuration. + sdnotify.Ready() +} + +func main() { + log.Println("starting...") + time.Sleep(time.Second) + log.Println("started.") + + // Tells the service manager that service startup is finished. + sdnotify.Ready() + + go func() { + tick := time.Tick(30 * time.Second) + for { + <-tick + log.Println("watchdog reporting") + sdnotify.Watchdog() + } + }() + + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + for sig := range sigCh { + if sig == syscall.SIGHUP { + reload() + } else { + break + } + } + + // Tells the service manager that the service is beginning its shutdown. + sdnotify.Stopping() + + log.Println("existing...") + time.Sleep(time.Second) +} -- cgit v1.2.3