Skip to content

Commit f3d0f70

Browse files
committed
cmd/dockerd: sd_notify STOPPING=1 when shutting down
Signal systemd when we start shutting down to complement the "READY" notify that was originally implemented in 97088eb From [sd_notify(3)](https://www.freedesktop.org/software/systemd/man/sd_notify.html#STOPPING=1) > STOPPING=1 > Tells the service manager that the service is beginning its shutdown. This is useful > to allow the service manager to track the service's internal state, and present it to > the user. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent aa1ada6 commit f3d0f70

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

cmd/dockerd/daemon.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
184184
}, logrus.StandardLogger())
185185

186186
// Notify that the API is active, but before daemon is set up.
187-
preNotifySystem()
187+
preNotifyReady()
188188

189189
pluginStore := plugin.NewStore()
190190

@@ -242,13 +242,15 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
242242
go cli.api.Wait(serveAPIWait)
243243

244244
// after the daemon is done setting up we can notify systemd api
245-
notifySystem()
245+
notifyReady()
246246

247247
// Daemon is fully initialized and handling API traffic
248248
// Wait for serve API to complete
249249
errAPI := <-serveAPIWait
250250
c.Cleanup()
251251

252+
// notify systemd that we're shutting down
253+
notifyStopping()
252254
shutdownDaemon(d)
253255

254256
// Stop notification processing and any background processes

cmd/dockerd/daemon_freebsd.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package main
22

3-
// preNotifySystem sends a message to the host when the API is active, but before the daemon is
4-
func preNotifySystem() {
3+
// preNotifyReady sends a message to the host when the API is active, but before the daemon is
4+
func preNotifyReady() {
55
}
66

7-
// notifySystem sends a message to the host when the server is ready to be used
8-
func notifySystem() {
7+
// notifyReady sends a message to the host when the server is ready to be used
8+
func notifyReady() {
9+
}
10+
11+
// notifyStopping sends a message to the host when the server is shutting down
12+
func notifyStopping() {
913
}

cmd/dockerd/daemon_linux.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ package main
22

33
import systemdDaemon "github.com/coreos/go-systemd/v22/daemon"
44

5-
// preNotifySystem sends a message to the host when the API is active, but before the daemon is
6-
func preNotifySystem() {
5+
// preNotifyReady sends a message to the host when the API is active, but before the daemon is
6+
func preNotifyReady() {
77
}
88

9-
// notifySystem sends a message to the host when the server is ready to be used
10-
func notifySystem() {
9+
// notifyReady sends a message to the host when the server is ready to be used
10+
func notifyReady() {
1111
// Tell the init daemon we are accepting requests
1212
go systemdDaemon.SdNotify(false, systemdDaemon.SdNotifyReady)
1313
}
14+
15+
// notifyStopping sends a message to the host when the server is shutting down
16+
func notifyStopping() {
17+
go systemdDaemon.SdNotify(false, systemdDaemon.SdNotifyStopping)
18+
}

cmd/dockerd/daemon_windows.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func getDaemonConfDir(root string) (string, error) {
2727
return filepath.Join(root, `\config`), nil
2828
}
2929

30-
// preNotifySystem sends a message to the host when the API is active, but before the daemon is
31-
func preNotifySystem() {
30+
// preNotifyReady sends a message to the host when the API is active, but before the daemon is
31+
func preNotifyReady() {
3232
// start the service now to prevent timeouts waiting for daemon to start
3333
// but still (eventually) complete all requests that are sent after this
3434
if service != nil {
@@ -39,8 +39,12 @@ func preNotifySystem() {
3939
}
4040
}
4141

42-
// notifySystem sends a message to the host when the server is ready to be used
43-
func notifySystem() {
42+
// notifyReady sends a message to the host when the server is ready to be used
43+
func notifyReady() {
44+
}
45+
46+
// notifyStopping sends a message to the host when the server is shutting down
47+
func notifyStopping() {
4448
}
4549

4650
// notifyShutdown is called after the daemon shuts down but before the process exits.

0 commit comments

Comments
 (0)