Systemd scripts
Systemd scripts (/etc/systemd/*) are used to control services, e.g. apache, sshd, networking etc.
You can also create your own systemd scripts to control your custom services, and it’s not that hard to do.
You use systemd as follows:
# From the command line
$ systemctl start sshd
$ systemctl stop sshd
$ systemctl restart sshd
$ systemctl status sshd
# More detailed status of the last systemd output use:
$ journalctl -xe
Below you will find a simple systemd script for a custom service.
I used this for my razer gear.
# Razer daemon
[Unit]
# Just a description
Description=Razer Keyboard Daemon
# When to start the daemon
# Here, network and auditd need to start first
After=network.target auditd.service
# Server options
[Service]
EnvironmentFile=-/etc/default/razer_bcd
ExecStartPre=/usr/share/razer_bcd/systemd_helpers.sh bind
ExecStart=/usr/sbin/razer_bcd --pid-file /var/run/razer_bcd.pid
ExecStopPost=/usr/share/razer_bcd/systemd_helpers.sh unbind
KillMode=process
TimeoutStopSec=30
Type=forking
PIDFile=/var/run/razer_bcd.pid
[Install]
# multi-user "wants" this daemon
WantedBy=multi-user.target
# Just an alias
Alias=razer_bcd.service
When you create a systemd script, you also need to enable it to let it start on boot.
You do this like this (Using razer_bcd.service):
$ systemctl enable razer_bcd.service
# Or
$ systemctl enable razer_bcd