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.