sweetbbak / go-daemon-template

A template for a Linux Daemon in Golang. The daemon listens on a Unix socket for commands, responds to os Signals for start/stop/reload and has proper logging.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Daemon

This is an extension of the github.com/sevlyar/go-daemon library. It is an example and a template of how to create a simple daemon that behaves how you would expect a Unix daemon to behave.

first you run the daemon and it forks itself into the background. Then, you can send signals to the daemon to make it quit, reload or stop. But we also want to be able to send commands to a daemon... so I've added a simple Client Server that communicates over a Unix socket. After forking the daemon off into the background it will start a listener Unix socket, you can then re-run the same binary with different flags/args and the daemon will process those commands.

Fork it:

./daemon

Send a command:

./daemon -e "notify-send hello world"

you can process these commands and flags like you would with any other golang program. The limits are your imagination here. An example would be asking a wall-paper daemon to change the wallpaper. This is all handled in server.go

Reload the daemon configuration:

./daemon -s reload

Stop the daemon cleanly:

./daemon -s stop

About

A template for a Linux Daemon in Golang. The daemon listens on a Unix socket for commands, responds to os Signals for start/stop/reload and has proper logging.


Languages

Language:Go 98.2%Language:Just 1.8%