systemd: add notify support
That way, we can reliably know when the daemon is ready.
Steven Allen committed
Sep 24, 2019 at 20:30 UTC
87f2e38017a0965d285a1ab10f64b6afe1277dc3
4 files changed
+25
cmd/ipfs/daemon.go
+2
@@ -411,10 +411,12 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
411
412
// The daemon is *finally* ready.
413
fmt.Printf("Daemon is ready\n")
414
+ notifyReady()
415
416
// Give the user some immediate feedback when they hit C-c
417
go func() {
418
<-req.Context.Done()
419
+ notifyStopping()
420
fmt.Println("Received interrupt signal, shutting down...")
421
fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
422
}()
cmd/ipfs/daemon_linux.go
new
+15
@@ -0,0 +1,15 @@
1
+// +build linux
2
+
3
+package main
4
+
5
+import (
6
+ daemon "github.com/coreos/go-systemd/daemon"
7
+)
8
+
9
+func notifyReady() {
10
+ _, _ = daemon.SdNotify(false, daemon.SdNotifyReady)
11
+}
12
+
13
+func notifyStopping() {
14
+ _, _ = daemon.SdNotify(false, daemon.SdNotifyStopping)
15
+}
cmd/ipfs/daemon_other.go
new
+7
@@ -0,0 +1,7 @@
1
+// +build !linux
2
+
3
+package main
4
+
5
+func notifyReady() {}
6
+
7
+func notifyStopping() {}
misc/systemd/ipfs.service
+1
@@ -2,6 +2,7 @@
2
Description=IPFS Daemon
3
4
[Service]
5
+Type=notify
6
ExecStart=/usr/bin/ipfs daemon --init --migrate
7
KillSignal=SIGINT
8