From 5f580a148a73e996851b711426e0759fa1f8baef Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 13 Nov 2020 22:54:30 +0800 Subject: [PATCH] cosmovisor: pass quit signals to subprocess (#7776) fix #7740 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- cosmovisor/process.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cosmovisor/process.go b/cosmovisor/process.go index 055c4ebfc657..cfd201e2be99 100644 --- a/cosmovisor/process.go +++ b/cosmovisor/process.go @@ -4,9 +4,13 @@ import ( "bufio" "fmt" "io" + "log" + "os" "os/exec" + "os/signal" "strings" "sync" + "syscall" ) // LaunchProcess runs a subprocess and returns when the subprocess exits, @@ -39,6 +43,15 @@ func LaunchProcess(cfg *Config, args []string, stdout, stderr io.Writer) (bool, return false, fmt.Errorf("launching process %s %s: %w", bin, strings.Join(args, " "), err) } + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGQUIT, syscall.SIGTERM) + go func() { + sig := <-sigs + if err := cmd.Process.Signal(sig); err != nil { + log.Fatal(err) + } + }() + // three ways to exit - command ends, find regexp in scanOut, find regexp in scanErr upgradeInfo, err := WaitForUpgradeOrExit(cmd, scanOut, scanErr) if err != nil {