diff options
| author | Christine Dodrill <me@christine.website> | 2019-01-11 14:01:07 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-01-11 14:01:07 -0800 |
| commit | 22e991056b9144f0ba9d841e79dcb87641cd35bb (patch) | |
| tree | dfef723e00ba51649e134a53e30ebb2dca31953d | |
| parent | e50b910bacbc2a2fe6423d26a953df6ed911cff0 (diff) | |
| download | x-22e991056b9144f0ba9d841e79dcb87641cd35bb.tar.xz x-22e991056b9144f0ba9d841e79dcb87641cd35bb.zip | |
s6: add signaling package
| -rw-r--r-- | s6/signal.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/s6/signal.go b/s6/signal.go new file mode 100644 index 0000000..f754bbe --- /dev/null +++ b/s6/signal.go @@ -0,0 +1,37 @@ +// Package s6 allows Go programs to signal readiness to the s6[1] suite of system +// supervision tools. This should be run in func main. +// +// [1]: http://skarnet.org/software/s6/index.html +package s6 + +import ( + "errors" + "flag" + "os" +) + +var ( + ErrCantFindNotificationFD = errors.New("s6: can't find notification file descriptor") + notificationFD = flag.Int("notification-fd", 0, "notification file descriptor") +) + +// Signal signals readiness to s6. +// +// See: http://skarnet.org/software/s6/notifywhenup.html +func Signal() error { + var err error + + // If this is unset, we probably don't care about notifying s6. + if *notificationFD == 0 { + return nil + } + + fout := os.NewFile(uintptr(*notificationFD), "s6-notification") + if fout == nil { + return ErrCantFindNotificationFD + } + defer fout.Close() + + _, err = fout.Write([]byte("\n")) + return err +} |
