
For a program of yours (a Node.js app, a Python script, a bot) to start with the server and come back by itself if it dies, you write a unit file in /etc/systemd/system/, reload systemd and enable the service with systemctl enable --now. It is the native way on any modern Linux, with nothing extra to install. For Node.js apps there is also PM2 (keeping a Node.js app running with PM2); systemd covers everything else, and Node too.
Step by step
|
|
|
|
|
|
|
The unit’s lines, in words
| Line | What it is for |
| After=network.target | Starts only after the network is ready. |
| User= | Who runs the program. Never root, unless it truly needs it. |
| ExecStart= | The command, with the program’s full path. systemd uses neither your PATH nor your terminal. |
| Restart=on-failure | Starts again if it ends with an error; does not if you stopped it on purpose. |
| EnvironmentFile= | Reads variables from a file instead of writing them in the unit (which any user can read). |
| WantedBy=multi-user.target | What makes enable start it at the server’s normal boot. |
| ExecStart is not a terminal. Redirections, && and ~ do not work as they do at the prompt; use absolute paths and, if you need several commands, put them in a script and run the script. If you see “status=203/EXEC”, the path is wrong: reading systemctl status. |
| Changed the unit and nothing changed? You are missing sudo systemctl daemon-reload. And a unit that gets “Permission denied” reading a folder is permissions or SELinux: file permissions. |
| Scheduling with a timer instead of cron: systemd schedules too (.timer files), but for simple jobs cron is still the most direct: when cron does not run. |
|
Does the program run by hand and fail as a service, and you have read the log? Show us the error text and what changed since it worked. Open a support ticket |
|
SEE ALSO A service will not start: reading systemctl status Where the logs are on a Linux VPS |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from £5.28/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











