Create Your Own Service
As a developer, you may need to wrap a program you’re writing into a service, which can be more easily managed than a manually-run program. Let’s walk through the process:
- Ensure that you have an executable file copied to a place that is in the default
$PATH
:/usr/local/bin/yourprogram
. - Create the following systemd unit file at
/etc/systemd/system/yourprogram.service
:
[Unit]
Description=Your program description.
After=network-online.target
[Service]
Type=exec
ExecStart=/usr/local/bin/yourprogram
Restart=on-failure
[Install]
WantedBy=multi-user.target
Have systemd re-read its config files to make sure it sees the new service Unit you’ve defined:
$ sudo systemd daemon-reload
Now you can manage this like any other systemd service:
systemctl start yourprogram
systemctl status yourprogram
systemctl stop yourprogram
systemctl enable yourprogram
systemctl disable yourprogram
That’s all you need for an extremely simple service –...