Systemd recipe for simple daemons

In the previous post we discussed about upstart job files.
In this post will do the same with Sytemd.

If your daemon honours the same conditions of the previous post:

  • don’t fork;
  • can simply been stopped by a SIGSTOP
  • logs to the console;

then systemd calls that daemons “simple”, and you should create a simple systemd unit file like this:

[Unit]
Description=Your description here
After=network.target

[Service]
User=the user the daemon will run as
Env=your environment variables here
ExecStart=your daemon file here

[Install]
WantedBy=multi-user.target

You should place this file in /usr/lib/systemd/system with name [daemonname].service.
Now you can use the following commands:

$ systemd start <daemonname>  # Start this service now
$ systemd stop <daemonname>   # Stop this service now
$ systemd status <daemonname> # Get this daemon status
$ journalctl -u <daemonname>  # Get the stdout of your daemon 

If you want your service to be started in the boot process you can use this command:

$ systemd enable <daemonname>

Systemd, from this point of view, is simple and easy.

Systemd recipe for simple daemons

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s