Skip to content

Commit

Permalink
restart helper: give container process some time to shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Maarten Deprez <[email protected]>
  • Loading branch information
Maarten Deprez committed Jan 15, 2024
1 parent 26edf30 commit e02449d
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 e02449d

Please sign in to comment.