From 87f2e38017a0965d285a1ab10f64b6afe1277dc3 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 24 Sep 2019 20:30:37 -0700 Subject: [PATCH] systemd: add notify support That way, we can reliably know when the daemon is ready. --- cmd/ipfs/daemon.go | 2 ++ cmd/ipfs/daemon_linux.go | 15 +++++++++++++++ cmd/ipfs/daemon_other.go | 7 +++++++ misc/systemd/ipfs.service | 1 + 4 files changed, 25 insertions(+) create mode 100644 cmd/ipfs/daemon_linux.go create mode 100644 cmd/ipfs/daemon_other.go diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 7b0197bbc..14220060b 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -411,10 +411,12 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment // The daemon is *finally* ready. fmt.Printf("Daemon is ready\n") + notifyReady() // Give the user some immediate feedback when they hit C-c go func() { <-req.Context.Done() + notifyStopping() fmt.Println("Received interrupt signal, shutting down...") fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)") }() diff --git a/cmd/ipfs/daemon_linux.go b/cmd/ipfs/daemon_linux.go new file mode 100644 index 000000000..f269e5f95 --- /dev/null +++ b/cmd/ipfs/daemon_linux.go @@ -0,0 +1,15 @@ +// +build linux + +package main + +import ( + daemon "github.com/coreos/go-systemd/daemon" +) + +func notifyReady() { + _, _ = daemon.SdNotify(false, daemon.SdNotifyReady) +} + +func notifyStopping() { + _, _ = daemon.SdNotify(false, daemon.SdNotifyStopping) +} diff --git a/cmd/ipfs/daemon_other.go b/cmd/ipfs/daemon_other.go new file mode 100644 index 000000000..4ffdd8b8e --- /dev/null +++ b/cmd/ipfs/daemon_other.go @@ -0,0 +1,7 @@ +// +build !linux + +package main + +func notifyReady() {} + +func notifyStopping() {} diff --git a/misc/systemd/ipfs.service b/misc/systemd/ipfs.service index e3dae25c9..0ee585ac6 100644 --- a/misc/systemd/ipfs.service +++ b/misc/systemd/ipfs.service @@ -2,6 +2,7 @@ Description=IPFS Daemon [Service] +Type=notify ExecStart=/usr/bin/ipfs daemon --init --migrate KillSignal=SIGINT