wait for signal

This commit is contained in:
Oskar Thoren 2021-06-07 17:33:27 +08:00
parent fd118a12bf
commit cd3e764f89
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
1 changed files with 22 additions and 0 deletions

22
main.go
View File

@ -10,6 +10,8 @@ import (
"bytes"
"os"
"os/exec"
"os/signal"
"syscall"
"net/http"
)
@ -33,6 +35,19 @@ type DebugResult struct {
}
func main() {
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
// Waiting for signal
go func() {
sig := <-sigs
fmt.Println()
fmt.Println(sig)
done <- true
}()
cmd := exec.Command("./wakunode2")
outfile, err := os.Create("./wakunode2.log")
@ -98,4 +113,11 @@ func main() {
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
fmt.Println("exiting")
}