Creating services for Linux with systemd

Posted in Unix on October 15th, 2012 by phoenixdigital

Setting up services to start on boot is pretty straight forward.

You will need to create a service file in /lib/systemd/system/
vi /lib/systemd/system/your-service-name.service

then create a symbolic link for this file to /etc/systemd/system/
ln -s /lib/systemd/system/your-service-name.service /etc/systemd/system/your-service-name.service

Use the following command to reload any changes
systemctl daemon-reload

This command to start your service
systemctl start your-service-name.service

This command to enable your service on boot
systemctl enable your-service-name.service

If you run into any issues check /var/log/messages for any errors
tail /var/log/messages

Two example service files

[Unit]
Description=Polling weather station for live weather data
After=syslog.target network.target

[Service]
User=phoenix
Type=simple
ExecStart=/home/phoenix/weather/data/start.sh
KillSignal=SIGHUP

[Install]
WantedBy=multi-user.target

or

[Unit]
Description=PyTivo streaming service
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/var/lib/pytivo/pyTivo.py

[Install]
WantedBy=multi-user.target

Ref: http://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/