Created
May 1, 2019 02:09
-
-
Save phemmer/46a3d2c73f071b7216ab6adb4b833cd6 to your computer and use it in GitHub Desktop.
Attempt to test systemd notify reload failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/signal" | |
"syscall" | |
"time" | |
"github.com/coreos/go-systemd/daemon" | |
) | |
func main() { | |
sigchan := make(chan os.Signal, 1) | |
signal.Notify(sigchan) | |
daemon.SdNotify(false, daemon.SdNotifyReady) | |
fmt.Printf("Started\n") | |
for { | |
sig := <-sigchan | |
switch sig { | |
case syscall.SIGUSR1: | |
fmt.Printf("Received SIGUSR1\n") | |
time.Sleep(time.Second) | |
daemon.SdNotify(false, daemon.SdNotifyReloading) | |
fmt.Printf("Sent reloading notification\n") | |
time.Sleep(time.Second) | |
daemon.SdNotify(false, fmt.Sprintf("ERRNO=%d", syscall.EINVAL)) | |
fmt.Printf("Sent error\n") | |
case syscall.SIGTERM, syscall.SIGINT: | |
fmt.Printf("Received %s\n", sig) | |
time.Sleep(time.Second) | |
daemon.SdNotify(false, daemon.SdNotifyStopping) | |
fmt.Printf("Sent stopping notification\n") | |
time.Sleep(time.Second) | |
os.Exit(0) | |
default: | |
fmt.Printf("Unhandled signal %s\n", sig) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Service] | |
Type=notify | |
ExecStart=/tmp/test | |
ExecReload=/bin/kill -USR1 $MAINPID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment