A daemon package for use with Go services without any dependencies (except for golang.org/x/sys/windows
)
- Use
install
anduninstall
service file on Linux (SystemD, SystemV, UpStart), MacOS and FreeBSD - More control:
start
,stop
,restart
,reload
for all supported OS andpause
andcontinue
for Windows - Unified interface for all supported OS
go get -u github.com/nsemikov/go-daemon@latest
Create config for daemon:
cfg := daemon.NewConfig(
daemon.WithName("cmd_example"),
daemon.WithDescription("Command Line daemon example"),
daemon.WithStartHdlr(start),
daemon.WithStopHdlr(stop),
// add more options if you need
)
Create daemon:
d, err := daemon.New(cfg)
And then run it:
err = d.Run()
See the
examples
directory for more complete examples.