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 --- .../LICENSE | 21 ++++++++ .../README.md | 15 ++++++ .../notify.go | 9 ++++ .../notify_linux.go | 23 +++++++++ .../sample/main.go | 57 ++++++++++++++++++++++ .../sample/sample.service | 13 +++++ .../util.go | 39 +++++++++++++++ 7 files changed, 177 insertions(+) create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/LICENSE create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/README.md create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify.go create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify_linux.go create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/main.go create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/sample.service create mode 100644 dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/util.go (limited to 'dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd') diff --git a/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/LICENSE b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/LICENSE new file mode 100644 index 0000000..4654751 --- /dev/null +++ b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/LICENSE @@ -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. diff --git a/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/README.md b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/README.md new file mode 100644 index 0000000..ee85e05 --- /dev/null +++ b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/README.md @@ -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 \ No newline at end of file diff --git a/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify.go b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify.go new file mode 100644 index 0000000..f7d70e0 --- /dev/null +++ b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify.go @@ -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 +} diff --git a/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify_linux.go b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify_linux.go new file mode 100644 index 0000000..91d1efa --- /dev/null +++ b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/notify_linux.go @@ -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 +} 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) +} diff --git a/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/sample.service b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/sample.service new file mode 100644 index 0000000..895f8c1 --- /dev/null +++ b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/sample/sample.service @@ -0,0 +1,13 @@ +[Unit] +Description=sample + +[Service] +Type=notify +ExecStart=/path/to/sample +ExecStop=/bin/kill -SIGTERM $MAINPID +ExecReload=/bin/kill -SIGHUP $MAINPID +WatchdogSec=60s +Restart=on-failure + +[Install] +WantedBy = multi-user.target diff --git a/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/util.go b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/util.go new file mode 100644 index 0000000..71e1e92 --- /dev/null +++ b/dependencies/pkg/mod/github.com/okzk/sdnotify@v0.0.0-20180710141335-d9becc38acbd/util.go @@ -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") +} -- cgit v1.2.3