-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 924 Bytes
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"bigdis/config"
"bigdis/server"
"bigdis/storage"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/coreos/go-systemd/v22/daemon"
)
func main() {
configPath := flag.String("config", "", "path to config file")
flag.Parse()
// Init config
config.Init(*configPath)
storage.Init()
// systemd-notify ready
if _, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
panic(err)
}
go systemdNotify()
// Handle SIGTERM
sigterm := make(chan os.Signal, 1)
signal.Notify(sigterm, syscall.SIGTERM, syscall.SIGINT)
go func() {
<-sigterm
fmt.Println("\nStopping...")
// Perform cleanup here
daemon.SdNotify(false, daemon.SdNotifyStopping)
os.Exit(0)
}()
// Start server
if err := server.StartServer(); err != nil {
panic(err)
}
}
func systemdNotify() {
for {
daemon.SdNotify(false, daemon.SdNotifyWatchdog)
time.Sleep(10 * time.Second)
}
}