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.
The file can then be configured to start and stop the foo service. In this example, there is a shell script (foo.sh) that is used to start or stop the foo service.
[Unit] Description=foo service After=network.target [Service] Type=forking PIDFile=/path/to/foo.pid ExecStart=/path/to/foo.sh start ExecStop=/path/to/foo.sh stop [Install] WantedBy=multi-user.target
Reload the daemons, so that systemctl knows about foo.service.
Start and enable the service. Now, when the system is reboot, foo.service will invoke foo.sh 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: