About systemd service file generator
A systemd unit file lets Linux start your app on boot and restart it if it crashes.
Key fields
- ExecStart: the command to run.
- WorkingDirectory and User: where and as whom.
- Restart=on-failure to restart after errors.
Commands
- systemctl daemon-reload after adding the file.
- systemctl enable --now myapp to start it now and on boot.
- journalctl -u myapp to read logs.
A worked example
A unit file has [Unit] with a description and After=network.target, [Service] with User=app, WorkingDirectory=/srv/app, ExecStart=/usr/bin/node server.js, Restart=on-failure and Environment=NODE_ENV=production, and [Install] with WantedBy=multi-user.target. Save it in /etc/systemd/system/app.service.
Then run
- sudo systemctl daemon-reload.
- sudo systemctl enable --now app.
- systemctl status app and journalctl -u app -f to check it.
Troubleshooting
If the service fails to start, run systemctl status app and read journalctl -u app -n 50. Common causes are a wrong path in ExecStart, a missing user and file permissions.
