Skip to content

Commit

Permalink
cosmovisor: pass quit signals to subprocess (#7776)
Browse files Browse the repository at this point in the history
fix #7740

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
yihuang and mergify[bot] authored Nov 13, 2020
1 parent 0b1a3ee commit 5f580a1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cosmovisor/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5f580a1

Please sign in to comment.