FreeKB - Linux Fundamentals Systemd service files
Linux Fundamentals - Systemd service files

On a systemd system, the /etc/systemd/system directory contains files and sub directories that are used to manage services. Let's say you want to create a service called foo. Create the foo.service file.

touch /etc/systemd/system/foo.service


The file can then be configured to start and stop the foo service. In this example, there is a shell script ( that is used to start or stop the foo service.

Description=foo service

ExecStart=/path/to/ start
ExecStop=/path/to/ stop



Reload the daemons, so that systemctl knows about foo.service.

systemctl daemon-reload


Start and enable the service. Now, when the system is reboot, foo.service will invoke start to start the foo service.

systemctl start foo.service
systemctl enable foo.service


ExecStartPre, ExecStart and ExecStop will return FAILURE when the command in question returns an exit code other than 0, like this.

Process: 12345 ExecStart=some bogus command (code=exited, status=1/FAILURE)


There are scenarios where you want to continue execution even when a command returns an exit code other than 0. In these scenarios, the - character can be used, like this:

ExecStart=-/path/to/ start


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter a79f4 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |