Skip to content

Commit af45484

Browse files
authored
Merge pull request #2789 from maartendeprez/helper-restart-timings
restart helper: give container process some time to shutdown
2 parents d0ae0ec + e02449d commit af45484

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

helper/util/restart_linux.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import (
1111
"syscall"
1212
"time"
1313

14+
"github.com/loft-sh/devspace/helper/util/stderrlog"
1415
"github.com/loft-sh/devspace/pkg/devspace/build/builder/restart"
1516
"github.com/pkg/errors"
17+
"k8s.io/apimachinery/pkg/util/wait"
1618
)
1719

1820
type containerRestarter struct {
@@ -69,8 +71,23 @@ func (*containerRestarter) RestartContainer() error {
6971
}
7072

7173
// kill the process group
72-
_ = syscall.Kill(-pgid, syscall.SIGINT)
73-
time.Sleep(2000)
74-
_ = syscall.Kill(-pgid, syscall.SIGKILL)
74+
procPath := "/proc/" + strconv.Itoa(pgid)
75+
76+
for _, sig := range []syscall.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL} {
77+
stderrlog.Infof("Sending %s signal...", sig.String())
78+
err = syscall.Kill(-pgid, sig)
79+
if err != nil {
80+
return nil
81+
}
82+
err = wait.PollImmediate(time.Second, 5*time.Second, func() (done bool, err error) {
83+
_, err = os.Stat(procPath)
84+
return os.IsNotExist(err), nil
85+
})
86+
if err == nil {
87+
return nil
88+
}
89+
}
90+
91+
stderrlog.Errorf("Timeout waiting for the process to terminate")
7592
return nil
7693
}

0 commit comments

Comments
 (0)