fix signal handling
This commit is contained in:
parent
10266f26ef
commit
54dcd30a3f
1 changed files with 11 additions and 3 deletions
14
main.go
14
main.go
|
|
@ -103,6 +103,10 @@ func nodeMain() {
|
|||
|
||||
// load keystore
|
||||
ks := crypto.NewLuxKeyStore(config.KeyStore)
|
||||
if err := ks.Load(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to laod keystore: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nodeKey, ok := ks.Get(nodeId)
|
||||
if !ok {
|
||||
|
|
@ -175,16 +179,20 @@ func nodeMain() {
|
|||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
signaling:
|
||||
for {
|
||||
sig := <-sigs
|
||||
fmt.Println(sig)
|
||||
switch sig {
|
||||
case syscall.SIGINT:
|
||||
break signaling
|
||||
case syscall.SIGTERM:
|
||||
// stop node daemon
|
||||
node.Stop()
|
||||
os.Exit(0)
|
||||
break signaling
|
||||
}
|
||||
}
|
||||
|
||||
// stop daemon
|
||||
node.Stop()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue