Apply for Free VPS

Writing systemd services that survive real life

27 Nov 2026 systemd reliability

Restart policy, ordering, limits and sandboxing for the programs you deploy.

A five-line unit file works until the first bad night. A few more lines help a lot.

Restart with sense

[Unit]
StartLimitIntervalSec=300
StartLimitBurst=5

[Service]
Restart=on-failure
RestartSec=5

This retries, but stops a broken program looping for ever.

Order and readiness

After=network-online.target waits for the network. It does not mean your database is ready, so make the program retry connections.

Stop cleanly

KillSignal=SIGTERM
TimeoutStopSec=30

Handle the signal: finish current work and exit.

Limit

MemoryMax=512M
CPUQuota=80%
TasksMax=200

Sandbox

NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/lib/myapp

systemd-analyze security myapp suggests more. Test after each change.

Log to the journal

Write to standard output and let the journal keep the logs. You get timestamps, filtering and rotation without extra work.

Prove it

Kill the process, reboot the server, and confirm it comes back both times.

Need a server to try this on?See VPS plans

More articles