Creating a Linux Service with Systemd


The best way to run something at startup on a linux machine is by creating a service. This process can be finnicky and error prone, so here is a quick guide.

First create a service file. This lives in /etc/systemd/system. If the service is called foo, name the file foo.service.


ExecStart=/path/to/binary with arguments


The line will tell systemd to enable the service once the system has booted.

Now enable the service using

systemctl enable foo.service
systemctl start foo.service

And check the status is enabled and not failed using service foo status. To see logs from your service, run journalctl -u foo.

← Back