Signal systemd when we start shutting down to complement the "READY" notify
that was originally implemented in 97088ebef7c638f8175d7c61934642eeb2c054c4
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>
| ... | ... |
@@ -184,7 +184,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
| 184 | 184 |
}, logrus.StandardLogger()) |
| 185 | 185 |
|
| 186 | 186 |
// Notify that the API is active, but before daemon is set up. |
| 187 |
- preNotifySystem() |
|
| 187 |
+ preNotifyReady() |
|
| 188 | 188 |
|
| 189 | 189 |
pluginStore := plugin.NewStore() |
| 190 | 190 |
|
| ... | ... |
@@ -242,13 +242,15 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
| 242 | 242 |
go cli.api.Wait(serveAPIWait) |
| 243 | 243 |
|
| 244 | 244 |
// after the daemon is done setting up we can notify systemd api |
| 245 |
- notifySystem() |
|
| 245 |
+ notifyReady() |
|
| 246 | 246 |
|
| 247 | 247 |
// Daemon is fully initialized and handling API traffic |
| 248 | 248 |
// Wait for serve API to complete |
| 249 | 249 |
errAPI := <-serveAPIWait |
| 250 | 250 |
c.Cleanup() |
| 251 | 251 |
|
| 252 |
+ // notify systemd that we're shutting down |
|
| 253 |
+ notifyStopping() |
|
| 252 | 254 |
shutdownDaemon(d) |
| 253 | 255 |
|
| 254 | 256 |
// Stop notification processing and any background processes |
| ... | ... |
@@ -1,9 +1,13 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 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() {
|
|
| 5 | 5 |
} |
| 6 | 6 |
|
| 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() {
|
|
| 9 | 13 |
} |
| ... | ... |
@@ -2,12 +2,17 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import systemdDaemon "github.com/coreos/go-systemd/v22/daemon" |
| 4 | 4 |
|
| 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() {
|
|
| 7 | 7 |
} |
| 8 | 8 |
|
| 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() {
|
|
| 11 | 11 |
// Tell the init daemon we are accepting requests |
| 12 | 12 |
go systemdDaemon.SdNotify(false, systemdDaemon.SdNotifyReady) |
| 13 | 13 |
} |
| 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 |
+} |
| ... | ... |
@@ -27,8 +27,8 @@ func getDaemonConfDir(root string) (string, error) {
|
| 27 | 27 |
return filepath.Join(root, `\config`), nil |
| 28 | 28 |
} |
| 29 | 29 |
|
| 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() {
|
|
| 32 | 32 |
// start the service now to prevent timeouts waiting for daemon to start |
| 33 | 33 |
// but still (eventually) complete all requests that are sent after this |
| 34 | 34 |
if service != nil {
|
| ... | ... |
@@ -39,8 +39,12 @@ func preNotifySystem() {
|
| 39 | 39 |
} |
| 40 | 40 |
} |
| 41 | 41 |
|
| 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() {
|
|
| 44 | 48 |
} |
| 45 | 49 |
|
| 46 | 50 |
// notifyShutdown is called after the daemon shuts down but before the process exits. |