/etc/systemd/system/myapp.service with a [Unit], [Service] (including ExecStart= and User=) and [Install] section, then run sudo systemctl daemon-reload and sudo systemctl enable --now myapp. systemd then starts your program at boot, restarts it if it crashes (with Restart=on-failure) and collects its output in journalctl -u myapp.
Before you start
- Connect with SSH as a sudo user. Root can leave out
sudo. - Your program must run in the foreground: started from a terminal, it keeps running until you press
Ctrl+C. Test it by hand first. - Know the full path of the program, for example
/usr/bin/node(find it withcommand -v node) or/opt/myapp/run.sh.
How to create a systemd service
1
Create a user for the app (recommended)
Running as its own user limits the damage if the app is compromised.Put your app in
/opt/myapp and make sure myapp owns it: sudo chown -R myapp:myapp /opt/myapp.2
Write the unit file
Ctrl+O, Enter, and exit with Ctrl+X.3
Check the file for mistakes
Restart=sometimes gives a line like Failed to parse service restart specifier, ignoring: sometimes.4
Load, start and enable it
What each line means
Other service types
Example: a Node.js or Python app
EnvironmentFile takes KEY=value lines. Protect it with sudo chmod 600 /opt/myapp/.env. For Node.js apps you can also use PM2; see Node.js with PM2.
How to check it worked
sudo kill <PID>. After RestartSec seconds, systemctl status shows a new PID.
How to change or remove the service
- Change it: edit the file, then
sudo systemctl daemon-reloadandsudo systemctl restart myapp. - Override a package’s service (for example nginx) instead of editing its file:
sudo systemctl edit nginx. Your settings go in a drop-in file that package updates don’t overwrite. - Remove it:
Frequently asked questions
Why does my service show “status=203/EXEC”?
systemd couldn’t runExecStart: the path is wrong, the file isn’t executable (chmod +x), or a script lacks a first line such as #!/bin/bash.
Why does my service start and then stop straight away?
The program goes into the background or exits. Use the app’s foreground option, or useType=forking for a classic daemon. Check journalctl -u myapp for errors.
Can I run a service as my own user without sudo?
Yes. Put the file in~/.config/systemd/user/ and use systemctl --user. To keep it running after you log out, run sudo loginctl enable-linger alex.
Should I use a systemd timer instead of cron?
Either works. Timers log to the journal and can catch up missed runs withPersistent=true; cron is quicker to set up. See schedule tasks with cron.
Related guides
VPS and dedicated server guides
Every server guide in one place.
Manage services with systemctl
Start, stop and enable services.
Read logs with journalctl
See your service’s output.
Deploy a Python app with Gunicorn
A complete systemd example.
Environment variables
Pass settings to your app.
Checked against the official systemd.service and systemd.unit manuals on 4 November 2026; the unit file was validated with
systemd-analyze verify (systemd 255) on Ubuntu 24.04 LTS. Starting the service was not tested because our test container doesn’t run systemd as its init system. Commands can differ on other distributions or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026