Implement proper shutdown logic
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -86,8 +86,11 @@ func daemon(stateDir string, concurrency, bufferSize int) error {
|
||||
w := containerd.NewWorker(supervisor, wg)
|
||||
go w.Start()
|
||||
}
|
||||
if err := setSubReaper(); err != nil {
|
||||
return err
|
||||
// only set containerd as the subreaper if it is not an init process
|
||||
if pid := os.Getpid(); pid != 1 {
|
||||
if err := setSubReaper(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// start the signal handler in the background.
|
||||
go startSignalHandler(supervisor, bufferSize)
|
||||
|
||||
@@ -34,8 +34,7 @@ func startSignalHandler(supervisor *containerd.Supervisor, bufferSize int) {
|
||||
for s := range signals {
|
||||
switch s {
|
||||
case syscall.SIGTERM, syscall.SIGINT:
|
||||
supervisor.Close()
|
||||
os.Exit(0)
|
||||
supervisor.Stop(signals)
|
||||
case syscall.SIGCHLD:
|
||||
exits, err := reap()
|
||||
if err != nil {
|
||||
@@ -46,6 +45,8 @@ func startSignalHandler(supervisor *containerd.Supervisor, bufferSize int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
supervisor.Close()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func reap() (exits []*containerd.Event, err error) {
|
||||
|
||||
Reference in New Issue
Block a user