Skip to content

Commit

Permalink
Add log entries for daemon startup/shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed May 6, 2019
1 parent 20ea894 commit 595987f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
return err
}

logrus.Info("Starting up")

cli.configFile = &opts.configFile
cli.flags = opts.flags

Expand Down Expand Up @@ -266,6 +268,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
return errors.Wrap(errAPI, "shutting down due to ServeAPI error")
}

logrus.Info("Daemon shutdown complete")
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/dockerd/daemon_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/docker/docker/pkg/homedir"
"github.com/docker/libnetwork/portallocator"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -152,6 +153,7 @@ func (cli *DaemonCli) initContainerD(ctx context.Context) (func(time.Duration) e
return nil, errors.Wrap(err, "could not determine whether the system containerd is running")
}
if !ok {
logrus.Debug("Containerd not running, starting daemon managed containerd")
opts, err := cli.getContainerdDaemonOpts()
if err != nil {
return nil, errors.Wrap(err, "failed to generate containerd options")
Expand All @@ -161,6 +163,7 @@ func (cli *DaemonCli) initContainerD(ctx context.Context) (func(time.Duration) e
if err != nil {
return nil, errors.Wrap(err, "failed to start containerd")
}
logrus.Debug("Started daemon managed containerd")
cli.Config.ContainerdAddr = r.Address()

// Try to wait for containerd to shutdown
Expand Down
13 changes: 7 additions & 6 deletions internal/test/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
return errors.Errorf("[%s] Daemon exited and never started", d.id)
case <-tick:
ctx, cancel := context.WithTimeout(context.TODO(), 2*time.Second)
req := req.WithContext(ctx)

resp, err := client.Do(req)
resp, err := client.Do(req.WithContext(ctx))
cancel()
if err != nil {
d.log.Logf("[%s] error pinging daemon on start: %v", d.id, err)
Expand Down Expand Up @@ -413,12 +411,16 @@ func (d *Daemon) Stop(t testingT) {
// If it timeouts, a SIGKILL is sent.
// Stop will not delete the daemon directory. If a purged daemon is needed,
// instantiate a new one with NewDaemon.
func (d *Daemon) StopWithError() error {
func (d *Daemon) StopWithError() (err error) {
if d.cmd == nil || d.Wait == nil {
return errDaemonNotStarted
}
defer func() {
d.log.Logf("[%s] Daemon stopped", d.id)
if err == nil {
d.log.Logf("[%s] Daemon stopped", d.id)
} else {
d.log.Logf("[%s] Error when stopping daemon: %v", d.id, err)
}
d.logFile.Close()
d.cmd = nil
}()
Expand Down Expand Up @@ -490,7 +492,6 @@ func (d *Daemon) Restart(t testingT, args ...string) {
// RestartWithError will restart the daemon by first stopping it and then starting it.
func (d *Daemon) RestartWithError(arg ...string) error {
if err := d.StopWithError(); err != nil {
d.log.Logf("[%s] Error when stopping daemon: %v", d.id, err)
return err
}
return d.StartWithError(arg...)
Expand Down

0 comments on commit 595987f

Please sign in to comment.