-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (49 loc) · 1.14 KB
/
main.go
File metadata and controls
54 lines (49 loc) · 1.14 KB
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 (
"net"
"os"
"os/signal"
"syscall"
pb "github.com/OpenPeeDeeP/ChessClock-Daemon/chessclock"
"github.com/OpenPeeDeeP/ChessClock-Daemon/store"
"github.com/ianschenck/envflag"
"github.com/rs/zerolog/log"
"google.golang.org/grpc"
)
var version string
var (
daemonConString string
maxFiles int
)
func init() {
envflag.StringVar(&daemonConString, "CCD_CONNECTION_STRING", "localhost:4242", "Connection string to the daemon")
envflag.IntVar(&maxFiles, "CCD_MAX_FILES", 5, "Maximum number of log files")
}
func main() {
envflag.Parse()
lis, err := net.Listen("tcp", daemonConString)
if err != nil {
log.Error().Str("con", daemonConString).Msg("failed to listen")
os.Exit(1)
}
grpcServer := grpc.NewServer()
ccd := NewDaemon(store.NewFileStore("OpenPeeDeeP", "ChessClock", maxFiles))
pb.RegisterChessClockServer(grpcServer, ccd)
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
)
go func() {
s := <-sigc
switch s {
case syscall.SIGTERM:
grpcServer.Stop()
default:
grpcServer.GracefulStop()
}
}()
grpcServer.Serve(lis)
}