Home / Configs / Servers / systemd service file

systemd service file example: run your app in the background

Run your app in the background and start it automatically at boot.

For Linux with systemd (Ubuntu 18.04+, Debian 10+, Fedora, CentOS 7+). Not for macOS or Windows.

A systemd service file tells Linux how to start your app, which user to run it as, and when to restart it. Enter your details below, save the file, and enable it with systemctl.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Not root, if you can avoid it

/etc/systemd/system/myapp.service
[Unit]
Description=My app
After=network.target

[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/usr/bin/node /var/www/myapp/server.js
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

How this setup works

Diagram: Server boots, then Your .service file, then Your app
Server boots (systemd starts) → Your .service file (says what to run) → Your app (restarts if it stops)

Step-by-step setup

  1. Create the file: sudo nano /etc/systemd/system/myapp.service and paste the config.
  2. Reload systemd: sudo systemctl daemon-reload.
  3. Start it now and at every boot: sudo systemctl enable --now myapp.
  4. Check it: systemctl status myapp.
  5. Watch the logs: journalctl -u myapp -f.

What the important lines mean

Common errors and how to fix them

status=203/EXEC
The program in ExecStart was not found or is not executable. Check the path: /usr/bin/node /var/www/myapp/server.js.
status=217/USER
The user www-data does not exist on this server.
Unit myapp.service not found
The file must end in .service and sit in /etc/systemd/system. Then run sudo systemctl daemon-reload.

Frequently asked questions

Where do I save a systemd service file?
In /etc/systemd/system/ with a name ending in .service, then run sudo systemctl daemon-reload.
How do I see the logs of a systemd service?
Run journalctl -u your-service -f to follow the log live.
What does status=203/EXEC mean?
systemd could not run the program in ExecStart. The path is wrong or the file is not executable. Use the full path and check permissions.

Written for: systemd 255, Ubuntu 24.04 · Updated 2026-10-02

Free tools that help

Fix a problem with this setup

More server configs

See all 41 config generators