cmd/dockerd/trap: log to logrus directly
Logging through a dependency-injected interface value was a vestige of
when Trap was in pkg/signal to avoid importing logrus in a reusable
package: cc4da81128
.
Now that Trap lives under cmd/dockerd, nobody will be importing this so
we no longer need to worry about minimizing the package's dependencies.
Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
0f3c5d3893
commit
993ca8c6de
3 changed files with 7 additions and 9 deletions
|
@ -183,7 +183,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
trap.Trap(func() {
|
||||
cli.stop()
|
||||
<-stopc // wait for daemonCli.start() to return
|
||||
}, logrus.StandardLogger())
|
||||
})
|
||||
|
||||
// Notify that the API is active, but before daemon is set up.
|
||||
preNotifyReady()
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/docker/cmd/dockerd/trap"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -18,7 +17,7 @@ func main() {
|
|||
trap.Trap(func() {
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(99)
|
||||
}, logrus.StandardLogger())
|
||||
})
|
||||
go func() {
|
||||
p, err := os.FindProcess(os.Getpid())
|
||||
if err != nil {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package trap // import "github.com/docker/docker/cmd/dockerd/trap"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -22,15 +23,13 @@ const (
|
|||
//
|
||||
// If SIGINT or SIGTERM are received 3 times, the process is terminated
|
||||
// immediately with an exit code of 128 + the signal number.
|
||||
func Trap(cleanup func(), logger interface {
|
||||
Info(args ...interface{})
|
||||
}) {
|
||||
func Trap(cleanup func()) {
|
||||
c := make(chan os.Signal, forceQuitCount)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
var interruptCount int
|
||||
for sig := range c {
|
||||
logger.Info(fmt.Sprintf("Processing signal '%v'", sig))
|
||||
logrus.Infof("Processing signal '%v'", sig)
|
||||
if interruptCount < forceQuitCount {
|
||||
interruptCount++
|
||||
// Initiate the cleanup only once
|
||||
|
@ -40,7 +39,7 @@ func Trap(cleanup func(), logger interface {
|
|||
continue
|
||||
}
|
||||
|
||||
logger.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received")
|
||||
logrus.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received")
|
||||
os.Exit(128 + int(sig.(syscall.Signal)))
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Add table
Reference in a new issue