Skip to content

Commit

Permalink
only sigterm if process still exists.
Browse files Browse the repository at this point in the history
wait up to 10 seconds for it to quit before force quitting.
  • Loading branch information
pyrofolium committed Nov 3, 2023
1 parent ac823c7 commit 027329f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/cardinal/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"os/signal"
"syscall"
"time"

"github.com/magefile/mage/sh"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -72,7 +73,19 @@ var devCmd = &cobra.Command{
return errCleanup
}

if cardinalExecCmd.ProcessState == nil && cardinalExecCmd.Process != nil {
isProcessRunning := func(cmd *exec.Cmd) bool {
return cardinalExecCmd.ProcessState == nil && cardinalExecCmd.Process != nil
}

//wait up to 10 seconds for it to quit.
for i := 0; i < 10; i++ {
if isProcessRunning(cardinalExecCmd) {
time.Sleep(1 * time.Second)
} else {
break
}
}
if isProcessRunning(cardinalExecCmd) {
err = cardinalExecCmd.Process.Signal(syscall.SIGTERM)
if err != nil {
return err
Expand Down

0 comments on commit 027329f

Please sign in to comment.