fix: Send SIGTERM to child process when parent gets terminated
This commit is contained in:
parent
66aeae6166
commit
ff7ac9ad75
1 changed files with 10 additions and 0 deletions
10
main.go
10
main.go
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
@ -46,6 +47,15 @@ func main() {
|
|||
fmt.Printf("failed to start: %s\n", err)
|
||||
}
|
||||
|
||||
sigs := make(chan os.Signal, 1)
|
||||
go func() {
|
||||
for {
|
||||
_ = <-sigs
|
||||
cmd.Process.Signal(syscall.SIGTERM)
|
||||
}
|
||||
}()
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
fmt.Printf("process exited with error: %s\n", err)
|
||||
|
|
Loading…
Reference in a new issue