Debian Codegraph @

dependencies/pkg/mod/github.com/okzk/[email protected]/sample/main.go

raw
1 package main
2
3 import (
4 "log"
5 "os"
6 "os/signal"
7 "syscall"
8 "time"
9
10 "github.com/okzk/sdnotify"
11 )
12
13 func reload() {
14 // Tells the service manager that the service is reloading its configuration.
15 sdnotify.Reloading()
16
17 log.Println("reloading...")
18 time.Sleep(time.Second)
19 log.Println("reloaded.")
20
21 // The service must also send a "READY" notification when it completed reloading its configuration.
22 sdnotify.Ready()
23 }
24
25 func main() {
26 log.Println("starting...")
27 time.Sleep(time.Second)
28 log.Println("started.")
29
30 // Tells the service manager that service startup is finished.
31 sdnotify.Ready()
32
33 go func() {
34 tick := time.Tick(30 * time.Second)
35 for {
36 <-tick
37 log.Println("watchdog reporting")
38 sdnotify.Watchdog()
39 }
40 }()
41
42 sigCh := make(chan os.Signal, 1)
43 signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
44 for sig := range sigCh {
45 if sig == syscall.SIGHUP {
46 reload()
47 } else {
48 break
49 }
50 }
51
52 // Tells the service manager that the service is beginning its shutdown.
53 sdnotify.Stopping()
54
55 log.Println("existing...")
56 time.Sleep(time.Second)
57 }