Skip to main content
To create a systemd service, save a unit file as /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 with command -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

Paste this example and change the paths:
Save with Ctrl+O, Enter, and exit with Ctrl+X.
3

Check the file for mistakes

No output means systemd found no problems. A typo such as 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

Follow its output live:
To test automatic restarts, find the main PID in the status output and kill it with 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-reload and sudo 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 run ExecStart: 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 use Type=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 with Persistent=true; cron is quicker to set up. See schedule tasks with cron.

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:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026