Sunday, March 9, 2014

Add a custom systemd service

We will write a startup script for mt-daapd in this section. This way, the music server will start at boot and "restart itself if crashes anytime". I guess I am tarting to like systemd. Anyway here is how to do it.

First create a service.

nano /etc/systemd/system/mt-daapd.service

Copy the lines given below and make changes as necessary

[Unit]
Description=Mt-daapd service

[Service]
PIDFile=/var/run/mt-daapd.pid
ExecStart=/usr/local/sbin/mt-daapd -c /usr/local/mt-daapd-svn-1696/contrib/mt-daapd.conf -P /var/run/mt-daapd.pid

Restart=on-abort

[Install]
WantedBy=multi-user.target

We can test the service by just typing

systemctl start mt-daapd.service

Then check the status of the service

systemctl status mt-daapd.service

If everything works as it should enable it at the boot level. It just creates a symbolic link, nothing fancy.

systemctl enable mt-daapd.service

No comments:

Post a Comment