/
signal.go
37 lines (31 loc) · 859 Bytes
/
signal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
}