mirror of
https://github.com/moby/moby.git
synced 2026-06-30 19:58:03 +00:00
cmd/dockerd: notifyShutdown: don't use Fatal log to prevent early exit ------------------------------------------------------------------------ Commit40868e263dadded this log for situations where the daemon failed to start, and where no event-log was created to discover the failure. However, it used a `Fatal` log which, when using logrus, not only logs a message, but also calls the [logger's Exit function][1], which defaults [to `os.Exit`][2]. The error passed to the `notifyShutdown` function can be the result of different steps in the service's lifecycle; `cli.start()` starts a long- lived process, and the error returned can be either because it failed to start the service, or an error produced while shutting down the service. We should reduce ambiguity here (which could be for `cli.Start()` to return whether the service was started in the first place). Regardless, we want code following the log-entry to be executed, to make sure that codepaths following the `notifyShutdown` (which could be (defer) statements or cleanup steps) are executed. This patch changes the log to an `Error`, which is non-fatal, and should make sure that at least the `service.stopped` is executed to signal the service no longer running. The logging is also moved out of the `notifyShutdown`. Disclaimer: this is with the assumption that calling `service.stopped` is always acceptable, even if the service is not running, or in other states. cmd/dockerd: preNotifyReady: return error instead of logging and exit ------------------------------------------------------------------------ Commit57aef3b490added support for running the daemon as a Windows service. As part of this, it introduced a log for situations where the service failed to start. However, it used a `Fatal` log for this purpose which, when using logrus, not only logs a message, but also calls the [logger's Exit function][1], which defaults [to `os.Exit`][2]. A result of this is that the daemon does an unclean shutdown, causing other code (which could be (defer) statements or cleanup steps) not to be executed. This patch updates the `preNotifyReady` to return the error instead of logging and exiting. `preNotifyReady` is executed as part of `cli.start()`, which has an error-return, and the error that is returned, is already logged by `runDaemon` (so logging it as part of `preNotifyReady` would result in the error being logged twice). [1]:5098132d84/vendor/github.com/sirupsen/logrus/entry.go (L336-L339)[2]:5098132d84/vendor/github.com/sirupsen/logrus/logger.go (L342-L348)- relates to https://github.com/moby/moby/pull/22340 cmd/dockerd: preNotifyReady: return error instead of logging and exit Commit57aef3b490added support for running the daemon as a Windows service. As part of this, it introduced a log for situations where the service failed to start. However, it used a `Fatal` log for this purpose which, when using logrus, not only logs a message, but also calls the [logger's Exit function][1], which defaults [to `os.Exit`][2]. A result of this is that the daemon does an unclean shutdown, causing other code (which could be (defer) statements or cleanup steps) not to be executed. This patch changes the `preNotifyReady` to [1]:5098132d84/vendor/github.com/sirupsen/logrus/entry.go (L336-L339)[2]:5098132d84/vendor/github.com/sirupsen/logrus/logger.go (L342-L348)Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
cdcgroups "github.com/containerd/cgroups/v3"
|
|
systemdDaemon "github.com/coreos/go-systemd/v22/daemon"
|
|
"github.com/docker/docker/daemon"
|
|
"github.com/docker/docker/daemon/config"
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// setPlatformOptions applies platform-specific CLI configuration options.
|
|
func setPlatformOptions(conf *config.Config) error {
|
|
if conf.RemappedRoot == "" {
|
|
return nil
|
|
}
|
|
|
|
containerdNamespace, containerdPluginNamespace, err := daemon.RemapContainerdNamespaces(conf)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
conf.ContainerdNamespace = containerdNamespace
|
|
conf.ContainerdPluginNamespace = containerdPluginNamespace
|
|
|
|
return nil
|
|
}
|
|
|
|
// preNotifyReady sends a message to the host when the API is active, but before the daemon is
|
|
func preNotifyReady() error {
|
|
return nil
|
|
}
|
|
|
|
// notifyReady sends a message to the host when the server is ready to be used
|
|
func notifyReady() {
|
|
// Tell the init daemon we are accepting requests
|
|
go systemdDaemon.SdNotify(false, systemdDaemon.SdNotifyReady)
|
|
}
|
|
|
|
// notifyStopping sends a message to the host when the server is shutting down
|
|
func notifyStopping() {
|
|
go systemdDaemon.SdNotify(false, systemdDaemon.SdNotifyStopping)
|
|
}
|
|
|
|
func validateCPURealtimeOptions(config *config.Config) error {
|
|
if config.CPURealtimePeriod == 0 && config.CPURealtimeRuntime == 0 {
|
|
return nil
|
|
}
|
|
if cdcgroups.Mode() == cdcgroups.Unified {
|
|
return errors.New("daemon-scoped cpu-rt-period and cpu-rt-runtime are not implemented for cgroup v2")
|
|
}
|
|
if !sysinfo.New().CPURealtime {
|
|
return errors.New("daemon-scoped cpu-rt-period and cpu-rt-runtime are not supported by the kernel")
|
|
}
|
|
return nil
|
|
}
|