2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2017-01-07 09:30:25 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/daemon/config"
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-01-07 09:30:25 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Reload reads configuration changes and modifies the
|
|
|
|
// daemon according to those changes.
|
|
|
|
// These are the settings that Reload changes:
|
|
|
|
// - Platform runtime
|
|
|
|
// - Daemon debug log level
|
|
|
|
// - Daemon max concurrent downloads
|
|
|
|
// - Daemon max concurrent uploads
|
2019-06-25 09:26:36 -04:00
|
|
|
// - Daemon max download attempts
|
2017-01-07 09:30:25 -05:00
|
|
|
// - Daemon shutdown timeout (in seconds)
|
|
|
|
// - Cluster discovery (reconfigure and restart)
|
|
|
|
// - Daemon labels
|
|
|
|
// - Insecure registries
|
|
|
|
// - Registry mirrors
|
|
|
|
// - Daemon live restore
|
|
|
|
func (daemon *Daemon) Reload(conf *config.Config) (err error) {
|
|
|
|
daemon.configStore.Lock()
|
|
|
|
attributes := map[string]string{}
|
|
|
|
|
|
|
|
defer func() {
|
2021-08-31 08:13:30 -04:00
|
|
|
if err == nil {
|
|
|
|
jsonString, _ := json.Marshal(&struct {
|
|
|
|
*config.Config
|
|
|
|
config.ProxyConfig
|
|
|
|
}{
|
|
|
|
Config: daemon.configStore,
|
|
|
|
ProxyConfig: config.ProxyConfig{
|
|
|
|
HTTPProxy: config.MaskCredentials(daemon.configStore.HTTPProxy),
|
|
|
|
HTTPSProxy: config.MaskCredentials(daemon.configStore.HTTPSProxy),
|
|
|
|
NoProxy: config.MaskCredentials(daemon.configStore.NoProxy),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logrus.Infof("Reloaded configuration: %s", jsonString)
|
|
|
|
}
|
Log active configuration when reloading
When succesfully reloading the daemon configuration, print a message
in the logs with the active configuration:
INFO[2018-01-15T15:36:20.901688317Z] Got signal to reload configuration, reloading from: /etc/docker/daemon.json
INFO[2018-01-14T02:23:48.782769942Z] Reloaded configuration: {"mtu":1500,"pidfile":"/var/run/docker.pid","data-root":"/var/lib/docker","exec-root":"/var/run/docker","group":"docker","deprecated-key-path":"/etc/docker/key.json","max-concurrent-downloads":3,"max-concurrent-uploads":5,"shutdown-timeout":15,"debug":true,"hosts":["unix:///var/run/docker.sock"],"log-level":"info","swarm-default-advertise-addr":"","metrics-addr":"","log-driver":"json-file","ip":"0.0.0.0","icc":true,"iptables":true,"ip-forward":true,"ip-masq":true,"userland-proxy":true,"disable-legacy-registry":true,"experimental":false,"network-control-plane-mtu":1500,"runtimes":{"runc":{"path":"docker-runc"}},"default-runtime":"runc","oom-score-adjust":-500,"default-shm-size":67108864,"default-ipc-mode":"shareable"}
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-01-15 11:11:05 -05:00
|
|
|
|
2017-01-07 09:30:25 -05:00
|
|
|
// we're unlocking here, because
|
|
|
|
// LogDaemonEventWithAttributes() -> SystemInfo() -> GetAllRuntimes()
|
|
|
|
// holds that lock too.
|
|
|
|
daemon.configStore.Unlock()
|
|
|
|
if err == nil {
|
|
|
|
daemon.LogDaemonEventWithAttributes("reload", attributes)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
Implement none, private, and shareable ipc modes
Since the commit d88fe447df0e8 ("Add support for sharing /dev/shm/ and
/dev/mqueue between containers") container's /dev/shm is mounted on the
host first, then bind-mounted inside the container. This is done that
way in order to be able to share this container's IPC namespace
(and the /dev/shm mount point) with another container.
Unfortunately, this functionality breaks container checkpoint/restore
(even if IPC is not shared). Since /dev/shm is an external mount, its
contents is not saved by `criu checkpoint`, and so upon restore any
application that tries to access data under /dev/shm is severily
disappointed (which usually results in a fatal crash).
This commit solves the issue by introducing new IPC modes for containers
(in addition to 'host' and 'container:ID'). The new modes are:
- 'shareable': enables sharing this container's IPC with others
(this used to be the implicit default);
- 'private': disables sharing this container's IPC.
In 'private' mode, container's /dev/shm is truly mounted inside the
container, without any bind-mounting from the host, which solves the
issue.
While at it, let's also implement 'none' mode. The motivation, as
eloquently put by Justin Cormack, is:
> I wondered a while back about having a none shm mode, as currently it is
> not possible to have a totally unwriteable container as there is always
> a /dev/shm writeable mount. It is a bit of a niche case (and clearly
> should never be allowed to be daemon default) but it would be trivial to
> add now so maybe we should...
...so here's yet yet another mode:
- 'none': no /dev/shm mount inside the container (though it still
has its own private IPC namespace).
Now, to ultimately solve the abovementioned checkpoint/restore issue, we'd
need to make 'private' the default mode, but unfortunately it breaks the
backward compatibility. So, let's make the default container IPC mode
per-daemon configurable (with the built-in default set to 'shareable'
for now). The default can be changed either via a daemon CLI option
(--default-shm-mode) or a daemon.json configuration file parameter
of the same name.
Note one can only set either 'shareable' or 'private' IPC modes as a
daemon default (i.e. in this context 'host', 'container', or 'none'
do not make much sense).
Some other changes this patch introduces are:
1. A mount for /dev/shm is added to default OCI Linux spec.
2. IpcMode.Valid() is simplified to remove duplicated code that parsed
'container:ID' form. Note the old version used to check that ID does
not contain a semicolon -- this is no longer the case (tests are
modified accordingly). The motivation is we should either do a
proper check for container ID validity, or don't check it at all
(since it is checked in other places anyway). I chose the latter.
3. IpcMode.Container() is modified to not return container ID if the
mode value does not start with "container:", unifying the check to
be the same as in IpcMode.IsContainer().
3. IPC mode unit tests (runconfig/hostconfig_test.go) are modified
to add checks for newly added values.
[v2: addressed review at https://github.com/moby/moby/pull/34087#pullrequestreview-51345997]
[v3: addressed review at https://github.com/moby/moby/pull/34087#pullrequestreview-53902833]
[v4: addressed the case of upgrading from older daemon, in this case
container.HostConfig.IpcMode is unset and this is valid]
[v5: document old and new IpcMode values in api/swagger.yaml]
[v6: add the 'none' mode, changelog entry to docs/api/version-history.md]
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2017-06-27 17:58:50 -04:00
|
|
|
if err := daemon.reloadPlatform(conf, attributes); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-01-07 09:30:25 -05:00
|
|
|
daemon.reloadDebug(conf, attributes)
|
2017-05-21 19:24:07 -04:00
|
|
|
daemon.reloadMaxConcurrentDownloadsAndUploads(conf, attributes)
|
2019-06-25 09:26:36 -04:00
|
|
|
if err := daemon.reloadMaxDownloadAttempts(conf, attributes); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-01-07 09:30:25 -05:00
|
|
|
daemon.reloadShutdownTimeout(conf, attributes)
|
2018-08-22 02:05:26 -04:00
|
|
|
daemon.reloadFeatures(conf, attributes)
|
2017-01-07 09:30:25 -05:00
|
|
|
|
|
|
|
if err := daemon.reloadLabels(conf, attributes); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-09 17:00:31 -04:00
|
|
|
if err := daemon.reloadAllowNondistributableArtifacts(conf, attributes); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-01-07 09:30:25 -05:00
|
|
|
if err := daemon.reloadInsecureRegistries(conf, attributes); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := daemon.reloadRegistryMirrors(conf, attributes); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := daemon.reloadLiveRestore(conf, attributes); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-15 16:35:30 -05:00
|
|
|
return daemon.reloadNetworkDiagnosticPort(conf, attributes)
|
2017-01-07 09:30:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// reloadDebug updates configuration with Debug option
|
|
|
|
// and updates the passed attributes
|
|
|
|
func (daemon *Daemon) reloadDebug(conf *config.Config, attributes map[string]string) {
|
|
|
|
// update corresponding configuration
|
|
|
|
if conf.IsValueSet("debug") {
|
|
|
|
daemon.configStore.Debug = conf.Debug
|
|
|
|
}
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
attributes["debug"] = fmt.Sprintf("%t", daemon.configStore.Debug)
|
|
|
|
}
|
|
|
|
|
2017-05-21 19:24:07 -04:00
|
|
|
// reloadMaxConcurrentDownloadsAndUploads updates configuration with max concurrent
|
2017-01-07 09:30:25 -05:00
|
|
|
// download and upload options and updates the passed attributes
|
2017-05-21 19:24:07 -04:00
|
|
|
func (daemon *Daemon) reloadMaxConcurrentDownloadsAndUploads(conf *config.Config, attributes map[string]string) {
|
2017-01-07 09:30:25 -05:00
|
|
|
// If no value is set for max-concurrent-downloads we assume it is the default value
|
|
|
|
// We always "reset" as the cost is lightweight and easy to maintain.
|
2019-01-10 09:34:02 -05:00
|
|
|
maxConcurrentDownloads := config.DefaultMaxConcurrentDownloads
|
2017-01-07 09:30:25 -05:00
|
|
|
if conf.IsValueSet("max-concurrent-downloads") && conf.MaxConcurrentDownloads != nil {
|
2019-01-10 09:34:02 -05:00
|
|
|
maxConcurrentDownloads = *conf.MaxConcurrentDownloads
|
2017-01-07 09:30:25 -05:00
|
|
|
}
|
2019-01-10 09:34:02 -05:00
|
|
|
daemon.configStore.MaxConcurrentDownloads = &maxConcurrentDownloads
|
2017-01-07 09:30:25 -05:00
|
|
|
logrus.Debugf("Reset Max Concurrent Downloads: %d", *daemon.configStore.MaxConcurrentDownloads)
|
|
|
|
|
|
|
|
// If no value is set for max-concurrent-upload we assume it is the default value
|
|
|
|
// We always "reset" as the cost is lightweight and easy to maintain.
|
2019-01-10 09:34:02 -05:00
|
|
|
maxConcurrentUploads := config.DefaultMaxConcurrentUploads
|
2017-01-07 09:30:25 -05:00
|
|
|
if conf.IsValueSet("max-concurrent-uploads") && conf.MaxConcurrentUploads != nil {
|
2019-01-10 09:34:02 -05:00
|
|
|
maxConcurrentUploads = *conf.MaxConcurrentUploads
|
2017-01-07 09:30:25 -05:00
|
|
|
}
|
2019-01-10 09:34:02 -05:00
|
|
|
daemon.configStore.MaxConcurrentUploads = &maxConcurrentUploads
|
2017-01-07 09:30:25 -05:00
|
|
|
logrus.Debugf("Reset Max Concurrent Uploads: %d", *daemon.configStore.MaxConcurrentUploads)
|
|
|
|
|
2019-01-10 09:34:02 -05:00
|
|
|
if daemon.imageService != nil {
|
|
|
|
daemon.imageService.UpdateConfig(&maxConcurrentDownloads, &maxConcurrentUploads)
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:52:47 -05:00
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
attributes["max-concurrent-downloads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentDownloads)
|
2017-01-07 09:30:25 -05:00
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
attributes["max-concurrent-uploads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentUploads)
|
|
|
|
}
|
|
|
|
|
2019-06-25 09:26:36 -04:00
|
|
|
// reloadMaxDownloadAttempts updates configuration with max concurrent
|
|
|
|
// download attempts when a connection is lost and updates the passed attributes
|
|
|
|
func (daemon *Daemon) reloadMaxDownloadAttempts(conf *config.Config, attributes map[string]string) error {
|
|
|
|
if err := config.ValidateMaxDownloadAttempts(conf); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no value is set for max-download-attempts we assume it is the default value
|
|
|
|
// We always "reset" as the cost is lightweight and easy to maintain.
|
|
|
|
maxDownloadAttempts := config.DefaultDownloadAttempts
|
|
|
|
if conf.IsValueSet("max-download-attempts") && conf.MaxDownloadAttempts != nil {
|
|
|
|
maxDownloadAttempts = *conf.MaxDownloadAttempts
|
|
|
|
}
|
|
|
|
daemon.configStore.MaxDownloadAttempts = &maxDownloadAttempts
|
|
|
|
logrus.Debugf("Reset Max Download Attempts: %d", *daemon.configStore.MaxDownloadAttempts)
|
|
|
|
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
attributes["max-download-attempts"] = fmt.Sprintf("%d", *daemon.configStore.MaxDownloadAttempts)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-01-07 09:30:25 -05:00
|
|
|
// reloadShutdownTimeout updates configuration with daemon shutdown timeout option
|
|
|
|
// and updates the passed attributes
|
|
|
|
func (daemon *Daemon) reloadShutdownTimeout(conf *config.Config, attributes map[string]string) {
|
|
|
|
// update corresponding configuration
|
|
|
|
if conf.IsValueSet("shutdown-timeout") {
|
|
|
|
daemon.configStore.ShutdownTimeout = conf.ShutdownTimeout
|
|
|
|
logrus.Debugf("Reset Shutdown Timeout: %d", daemon.configStore.ShutdownTimeout)
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
attributes["shutdown-timeout"] = fmt.Sprintf("%d", daemon.configStore.ShutdownTimeout)
|
|
|
|
}
|
|
|
|
|
|
|
|
// reloadLabels updates configuration with engine labels
|
|
|
|
// and updates the passed attributes
|
|
|
|
func (daemon *Daemon) reloadLabels(conf *config.Config, attributes map[string]string) error {
|
|
|
|
// update corresponding configuration
|
|
|
|
if conf.IsValueSet("labels") {
|
|
|
|
daemon.configStore.Labels = conf.Labels
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
if daemon.configStore.Labels != nil {
|
|
|
|
labels, err := json.Marshal(daemon.configStore.Labels)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
attributes["labels"] = string(labels)
|
|
|
|
} else {
|
|
|
|
attributes["labels"] = "[]"
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-05-09 17:00:31 -04:00
|
|
|
// reloadAllowNondistributableArtifacts updates the configuration with allow-nondistributable-artifacts options
|
|
|
|
// and updates the passed attributes.
|
|
|
|
func (daemon *Daemon) reloadAllowNondistributableArtifacts(conf *config.Config, attributes map[string]string) error {
|
|
|
|
// Update corresponding configuration.
|
|
|
|
if conf.IsValueSet("allow-nondistributable-artifacts") {
|
|
|
|
daemon.configStore.AllowNondistributableArtifacts = conf.AllowNondistributableArtifacts
|
2022-03-02 05:43:33 -05:00
|
|
|
if err := daemon.registryService.LoadAllowNondistributableArtifacts(conf.AllowNondistributableArtifacts); err != nil {
|
2017-05-09 17:00:31 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare reload event attributes with updatable configurations.
|
|
|
|
if daemon.configStore.AllowNondistributableArtifacts != nil {
|
|
|
|
v, err := json.Marshal(daemon.configStore.AllowNondistributableArtifacts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
attributes["allow-nondistributable-artifacts"] = string(v)
|
|
|
|
} else {
|
|
|
|
attributes["allow-nondistributable-artifacts"] = "[]"
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-01-07 09:30:25 -05:00
|
|
|
// reloadInsecureRegistries updates configuration with insecure registry option
|
|
|
|
// and updates the passed attributes
|
|
|
|
func (daemon *Daemon) reloadInsecureRegistries(conf *config.Config, attributes map[string]string) error {
|
|
|
|
// update corresponding configuration
|
|
|
|
if conf.IsValueSet("insecure-registries") {
|
|
|
|
daemon.configStore.InsecureRegistries = conf.InsecureRegistries
|
2022-03-02 05:43:33 -05:00
|
|
|
if err := daemon.registryService.LoadInsecureRegistries(conf.InsecureRegistries); err != nil {
|
2017-01-07 09:30:25 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
if daemon.configStore.InsecureRegistries != nil {
|
|
|
|
insecureRegistries, err := json.Marshal(daemon.configStore.InsecureRegistries)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
attributes["insecure-registries"] = string(insecureRegistries)
|
|
|
|
} else {
|
|
|
|
attributes["insecure-registries"] = "[]"
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// reloadRegistryMirrors updates configuration with registry mirror options
|
|
|
|
// and updates the passed attributes
|
|
|
|
func (daemon *Daemon) reloadRegistryMirrors(conf *config.Config, attributes map[string]string) error {
|
|
|
|
// update corresponding configuration
|
|
|
|
if conf.IsValueSet("registry-mirrors") {
|
|
|
|
daemon.configStore.Mirrors = conf.Mirrors
|
2022-03-02 05:43:33 -05:00
|
|
|
if err := daemon.registryService.LoadMirrors(conf.Mirrors); err != nil {
|
2017-01-07 09:30:25 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
if daemon.configStore.Mirrors != nil {
|
|
|
|
mirrors, err := json.Marshal(daemon.configStore.Mirrors)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
attributes["registry-mirrors"] = string(mirrors)
|
|
|
|
} else {
|
|
|
|
attributes["registry-mirrors"] = "[]"
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-07 01:55:31 -04:00
|
|
|
// reloadLiveRestore updates configuration with live restore option
|
2017-01-07 09:30:25 -05:00
|
|
|
// and updates the passed attributes
|
|
|
|
func (daemon *Daemon) reloadLiveRestore(conf *config.Config, attributes map[string]string) error {
|
|
|
|
// update corresponding configuration
|
|
|
|
if conf.IsValueSet("live-restore") {
|
|
|
|
daemon.configStore.LiveRestoreEnabled = conf.LiveRestoreEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
attributes["live-restore"] = fmt.Sprintf("%t", daemon.configStore.LiveRestoreEnabled)
|
|
|
|
return nil
|
|
|
|
}
|
2017-12-01 14:24:14 -05:00
|
|
|
|
2018-01-29 14:19:37 -05:00
|
|
|
// reloadNetworkDiagnosticPort updates the network controller starting the diagnostic if the config is valid
|
2017-12-01 14:24:14 -05:00
|
|
|
func (daemon *Daemon) reloadNetworkDiagnosticPort(conf *config.Config, attributes map[string]string) error {
|
2018-01-29 14:19:37 -05:00
|
|
|
if conf == nil || daemon.netController == nil || !conf.IsValueSet("network-diagnostic-port") ||
|
|
|
|
conf.NetworkDiagnosticPort < 1 || conf.NetworkDiagnosticPort > 65535 {
|
|
|
|
// If there is no config make sure that the diagnostic is off
|
|
|
|
if daemon.netController != nil {
|
|
|
|
daemon.netController.StopDiagnostic()
|
|
|
|
}
|
2017-12-01 14:24:14 -05:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-08 11:45:00 -04:00
|
|
|
// Enable the network diagnostic if the flag is set with a valid port within the range
|
2018-01-29 14:19:37 -05:00
|
|
|
logrus.WithFields(logrus.Fields{"port": conf.NetworkDiagnosticPort, "ip": "127.0.0.1"}).Warn("Starting network diagnostic server")
|
|
|
|
daemon.netController.StartDiagnostic(conf.NetworkDiagnosticPort)
|
|
|
|
|
2017-12-01 14:24:14 -05:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-22 02:05:26 -04:00
|
|
|
|
|
|
|
// reloadFeatures updates configuration with enabled/disabled features
|
|
|
|
func (daemon *Daemon) reloadFeatures(conf *config.Config, attributes map[string]string) {
|
|
|
|
// update corresponding configuration
|
|
|
|
// note that we allow features option to be entirely unset
|
|
|
|
daemon.configStore.Features = conf.Features
|
|
|
|
|
|
|
|
// prepare reload event attributes with updatable configurations
|
|
|
|
attributes["features"] = fmt.Sprintf("%v", daemon.configStore.Features)
|
|
|
|
}
|