Anatomy of a service file
Systemd service files live in/etc/systemd/system/ and end in .service. Here is a template you can adapt for any long-running app:
- User — which user the process runs as. Avoid
rootwhen possible. - WorkingDirectory — the app’s working directory, as if you had
cd’d there. - ExecStart — the command to run. Use absolute paths.
- Restart=on-failure — restart if the process exits with an error.
Create and enable a service
1
Write the service file
2
Reload systemd so it picks up the new file
3
Start the service
4
Enable it on boot
