cosmovisor: pass quit signals to subprocess (#7776)

fix #7740

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
yihuang 2020-11-13 22:54:30 +08:00 committed by GitHub
parent 0b1a3eed39
commit 5f580a148a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {