|
@@ -3,11 +3,9 @@ package trap // import "github.com/docker/docker/cmd/dockerd/trap"
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
"os"
|
|
"os"
|
|
- gosignal "os/signal"
|
|
|
|
|
|
+ "os/signal"
|
|
"sync/atomic"
|
|
"sync/atomic"
|
|
"syscall"
|
|
"syscall"
|
|
-
|
|
|
|
- "github.com/docker/docker/pkg/stack"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
// Trap sets up a simplified signal "trap", appropriate for common
|
|
// Trap sets up a simplified signal "trap", appropriate for common
|
|
@@ -17,7 +15,6 @@ import (
|
|
// - If SIGINT or SIGTERM are received, `cleanup` is called, then the process is terminated.
|
|
// - If SIGINT or SIGTERM are received, `cleanup` is called, then the process is terminated.
|
|
// - If SIGINT or SIGTERM are received 3 times before cleanup is complete, then cleanup is
|
|
// - If SIGINT or SIGTERM are received 3 times before cleanup is complete, then cleanup is
|
|
// skipped and the process is terminated immediately (allows force quit of stuck daemon)
|
|
// skipped and the process is terminated immediately (allows force quit of stuck daemon)
|
|
-// - A SIGQUIT always causes an exit without cleanup, with a goroutine dump preceding exit.
|
|
|
|
// - Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
|
|
// - Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
|
|
// the docker daemon is not restarted and also running under systemd.
|
|
// the docker daemon is not restarted and also running under systemd.
|
|
// Fixes https://github.com/docker/docker/issues/19728
|
|
// Fixes https://github.com/docker/docker/issues/19728
|
|
@@ -25,9 +22,8 @@ func Trap(cleanup func(), logger interface {
|
|
Info(args ...interface{})
|
|
Info(args ...interface{})
|
|
}) {
|
|
}) {
|
|
c := make(chan os.Signal, 1)
|
|
c := make(chan os.Signal, 1)
|
|
- // we will handle INT, TERM, QUIT, SIGPIPE here
|
|
|
|
- signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGPIPE}
|
|
|
|
- gosignal.Notify(c, signals...)
|
|
|
|
|
|
+ // we will handle INT, TERM, SIGPIPE here
|
|
|
|
+ signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGPIPE)
|
|
go func() {
|
|
go func() {
|
|
interruptCount := uint32(0)
|
|
interruptCount := uint32(0)
|
|
for sig := range c {
|
|
for sig := range c {
|
|
@@ -52,11 +48,8 @@ func Trap(cleanup func(), logger interface {
|
|
// 3 SIGTERM/INT signals received; force exit without cleanup
|
|
// 3 SIGTERM/INT signals received; force exit without cleanup
|
|
logger.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received")
|
|
logger.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received")
|
|
}
|
|
}
|
|
- case syscall.SIGQUIT:
|
|
|
|
- stack.Dump()
|
|
|
|
- logger.Info("Forcing docker daemon shutdown without cleanup on SIGQUIT")
|
|
|
|
}
|
|
}
|
|
- // for the SIGINT/TERM, and SIGQUIT non-clean shutdown case, exit with 128 + signal #
|
|
|
|
|
|
+ // for the SIGINT/TERM non-clean shutdown case, exit with 128 + signal #
|
|
os.Exit(128 + int(sig.(syscall.Signal)))
|
|
os.Exit(128 + int(sig.(syscall.Signal)))
|
|
}(sig)
|
|
}(sig)
|
|
}
|
|
}
|