forked from gluster/glusterd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (49 loc) · 1.22 KB
/
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
55
56
57
58
59
60
61
package main
import (
"os"
"os/signal"
"github.com/gluster/glusterd2/commands"
"github.com/gluster/glusterd2/context"
"github.com/gluster/glusterd2/etcdmgmt"
"github.com/gluster/glusterd2/rpc/server"
log "github.com/Sirupsen/logrus"
)
func main() {
log.Info("GlusterD starting")
// Starting etcd daemon upon starting of GlusterD
etcdCtx, err := etcdmgmt.StartETCD()
if err != nil {
log.WithField("Error", err).Fatal("Could not able to start etcd")
}
context.Init()
context.EtcdProcessCtx = etcdCtx
for _, c := range commands.Commands {
context.Rest.SetRoutes(c.Routes())
}
err = server.StartListener()
if err != nil {
log.Fatal("Could not register the listener. Aborting")
} else {
log.Debug("Registered RPC listener")
}
sigCh := make(chan os.Signal)
signal.Notify(sigCh)
go func() {
for s := range sigCh {
log.WithField("signal", s).Debug("Signal recieved")
switch s {
case os.Interrupt:
log.WithField("signal", s).Info("Recieved SIGTERM. Stopping GlusterD.")
context.Rest.Stop()
log.Info("Termintaing GlusterD.")
os.Exit(0)
default:
continue
}
}
}()
err = context.Rest.Listen()
if err != nil {
log.Fatal("Could not start GlusterD Rest Server. Aborting.")
}
}