stop node on signal
This commit is contained in:
parent
cd3e764f89
commit
09991ee15d
27
main.go
27
main.go
|
@ -34,6 +34,16 @@ type DebugResult struct {
|
||||||
ListenStr string
|
ListenStr string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func stopNode() {
|
||||||
|
// Since we have reference to same process we can also use cmd.Process.Kill()
|
||||||
|
strb, _ := ioutil.ReadFile("wakunode2.lock")
|
||||||
|
command := exec.Command("kill", string(strb))
|
||||||
|
command.Start()
|
||||||
|
log.Printf("stopping wakunode2 process %s", string(strb))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
done := make(chan bool, 1)
|
done := make(chan bool, 1)
|
||||||
|
@ -43,8 +53,8 @@ func main() {
|
||||||
// Waiting for signal
|
// Waiting for signal
|
||||||
go func() {
|
go func() {
|
||||||
sig := <-sigs
|
sig := <-sigs
|
||||||
fmt.Println()
|
log.Printf("received %s", sig)
|
||||||
fmt.Println(sig)
|
stopNode()
|
||||||
done <- true
|
done <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -107,17 +117,8 @@ func main() {
|
||||||
|
|
||||||
log.Printf("JSON RPC response listenStr: %s", res["listenStr"])
|
log.Printf("JSON RPC response listenStr: %s", res["listenStr"])
|
||||||
|
|
||||||
// Stop process
|
log.Printf("awaiting signal")
|
||||||
// Since we have reference to same process we can also use cmd.Process.Kill()
|
|
||||||
strb, _ := ioutil.ReadFile("wakunode2.lock")
|
|
||||||
command := exec.Command("kill", string(strb))
|
|
||||||
command.Start()
|
|
||||||
log.Printf("Stopping wakunode2 process")
|
|
||||||
|
|
||||||
log.Printf("Just ran subprocess %d, exiting\n", cmd.Process.Pid)
|
|
||||||
|
|
||||||
fmt.Println("awaiting signal")
|
|
||||||
<-done
|
<-done
|
||||||
fmt.Println("exiting")
|
log.Printf("exiting")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue