diff --git a/helper/util/restart_linux.go b/helper/util/restart_linux.go index 86ae4785a0..d543c26e8e 100644 --- a/helper/util/restart_linux.go +++ b/helper/util/restart_linux.go @@ -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 { @@ -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 }