systemd: add notify support

That way, we can reliably know when the daemon is ready.
This commit is contained in:
Steven Allen 2019-09-24 20:30:37 -07:00
parent a4914a4478
commit 87f2e38017
4 changed files with 25 additions and 0 deletions

View File

@ -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.)")
}()

15
cmd/ipfs/daemon_linux.go Normal file
View File

@ -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)
}

7
cmd/ipfs/daemon_other.go Normal file
View File

@ -0,0 +1,7 @@
// +build !linux
package main
func notifyReady() {}
func notifyStopping() {}

View File

@ -2,6 +2,7 @@
Description=IPFS Daemon
[Service]
Type=notify
ExecStart=/usr/bin/ipfs daemon --init --migrate
KillSignal=SIGINT