-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcloudkey.go
59 lines (48 loc) · 1.41 KB
/
cloudkey.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
55
56
57
58
59
package main
import (
"flag"
"fmt"
"os"
"os/signal"
_ "github.com/jnovack/go-version"
"github.com/tabalt/pidfile"
"github.com/coreos/pkg/flagutil"
"github.com/jnovack/cloudkey/display"
_ "github.com/jnovack/cloudkey/fonts"
)
var tags = map[string]string{
"SYSLOG_IDENTIFIER": "cloudkey",
}
var opts display.CmdLineOpts
func main() {
display.New(opts)
}
func init() {
flag.Float64Var(&opts.Delay, "delay", 7500, "delay in milliseconds between screens")
flag.BoolVar(&opts.Reset, "reset", false, "reset/clear the screen")
flag.BoolVar(&opts.Demo, "demo", false, "use fake data for display only")
flag.StringVar(&opts.Pidfile, "pidfile", "/var/run/zeromon.pid", "pidfile")
flag.BoolVar(&opts.Version, "version", false, "print version and exit")
flagutil.SetFlagsFromEnv(flag.CommandLine, "CLOUDKEY")
if opts.Version {
// already printed version
os.Exit(0)
}
pid, _ := pidfile.Create(opts.Pidfile)
// Setup Service
// https://fabianlee.org/2017/05/21/golang-running-a-go-binary-as-a-systemd-service-on-ubuntu-16-04/
fmt.Println("Starting cloudkey service")
// setup signal catching
sigs := make(chan os.Signal, 1)
// catch all signals since not explicitly listing
signal.Notify(sigs)
// method invoked upon seeing signal
go func() {
s := <-sigs
display.Shutdown()
fmt.Printf("Received signal '%s', shutting down\n", s)
fmt.Println("Stopping cloudkey service")
_ = pid.Clear()
os.Exit(1)
}()
}