-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (36 loc) · 949 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
package main
import (
"net"
"os"
"os/signal"
"syscall"
"github.com/TrustedPay/tp-term/pkg/tpterm"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
func main() {
lis, err := net.Listen("unix", "/tmp/tp-term.sock")
if err != nil {
logrus.Fatalf("failed to listen on /tmp/tp-term.sock: %v", err)
}
opts := []grpc.ServerOption{}
t := tpterm.NewTPTerm()
defer t.Shutdown()
grpcServer := grpc.NewServer(opts...)
tpterm.RegisterTPTermServer(grpcServer, t)
// Handle common process-killing signals so we can gracefully shut down:
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
go func(c chan os.Signal) {
// Wait for a SIGINT or SIGKILL:
<-c
println()
logrus.Warn("Shutting down...")
// Stop listening (and unlink the socket if unix type):
lis.Close()
// And we're done:
os.Exit(0)
}(sigc)
logrus.Infof("TP Term listening on %s", lis.Addr())
grpcServer.Serve(lis)
}