From cd3e764f89adb8ab9c9658661a0f446009b852d8 Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Mon, 7 Jun 2021 17:33:27 +0800 Subject: [PATCH] wait for signal --- main.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main.go b/main.go index dae8113..30b8a34 100644 --- a/main.go +++ b/main.go @@ -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") + }