Apply for Free VPS

Run an application as a systemd service

Updated 27 Nov 2026 deployment systemd

Keep your program running after you sign out and restart it if it fails.

Unit file

/etc/systemd/system/worker.service:

[Unit]
Description=My worker
After=network-online.target
Wants=network-online.target

[Service]
User=app
WorkingDirectory=/srv/worker
EnvironmentFile=/etc/worker.env
ExecStart=/srv/worker/bin/run
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full

[Install]
WantedBy=multi-user.target

ExecStart needs a full path.

Start it

sudo useradd --system --home /srv/worker app   # if the user does not exist
sudo chmod 600 /etc/worker.env
sudo systemctl daemon-reload
sudo systemctl enable --now worker

Watch it

systemctl status worker
journalctl -u worker -f

If it keeps restarting

Run the command by hand as the same user to see the error:

sudo -u app /srv/worker/bin/run

Check file permissions and environment variables.

Was this helpful?

Report outdated or incorrect information