mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 20:07:45 +08:00
systemd: add notify support
That way, we can reliably know when the daemon is ready.
This commit is contained in:
parent
a4914a4478
commit
87f2e38017
@ -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
15
cmd/ipfs/daemon_linux.go
Normal 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
7
cmd/ipfs/daemon_other.go
Normal file
@ -0,0 +1,7 @@
|
||||
// +build !linux
|
||||
|
||||
package main
|
||||
|
||||
func notifyReady() {}
|
||||
|
||||
func notifyStopping() {}
|
||||
@ -2,6 +2,7 @@
|
||||
Description=IPFS Daemon
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=/usr/bin/ipfs daemon --init --migrate
|
||||
KillSignal=SIGINT
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user