Implement proper shutdown logic

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2015-12-04 13:31:17 -08:00
parent a10aa91051
commit c10b3cde9f
6 changed files with 67 additions and 20 deletions

View File

@@ -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)

View File

@@ -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) {