Skip to content

Commit

Permalink
Merge pull request #2789 from maartendeprez/helper-restart-timings
Browse files Browse the repository at this point in the history
restart helper: give container process some time to shutdown
  • Loading branch information
lizardruss authored Jan 22, 2024
2 parents d0ae0ec + e02449d commit af45484
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions helper/util/restart_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"syscall"
"time"

"github.com/loft-sh/devspace/helper/util/stderrlog"
"github.com/loft-sh/devspace/pkg/devspace/build/builder/restart"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/wait"
)

type containerRestarter struct {
Expand Down Expand Up @@ -69,8 +71,23 @@ func (*containerRestarter) RestartContainer() error {
}

// kill the process group
_ = syscall.Kill(-pgid, syscall.SIGINT)
time.Sleep(2000)
_ = syscall.Kill(-pgid, syscall.SIGKILL)
procPath := "/proc/" + strconv.Itoa(pgid)

for _, sig := range []syscall.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL} {
stderrlog.Infof("Sending %s signal...", sig.String())
err = syscall.Kill(-pgid, sig)
if err != nil {
return nil
}
err = wait.PollImmediate(time.Second, 5*time.Second, func() (done bool, err error) {
_, err = os.Stat(procPath)
return os.IsNotExist(err), nil
})
if err == nil {
return nil
}
}

stderrlog.Errorf("Timeout waiting for the process to terminate")
return nil
}

0 comments on commit af45484

Please sign in to comment.