Cheatsheet Pages / systemd Cheatsheet
Anatomy of a systemd .service unit file — a complete, verified example
You are writing your first unit file and want a complete example that passes systemd-analyze verify.
Most management commands need sudo, and systemctl only works on a system actually booted with systemd — inside containers it fails with “System has not been booted with systemd as init system”. Every command was checked against systemd 255, and the example units pass systemd-analyze verify.
[Unit]
Description=MyApp demo service # human-readable name, shown by status
After=network.target # start AFTER the network is up (ordering only)
Wants=network.target # pull network.target in with us (weak requirement)
[Service]
Type=simple # ExecStart's main process IS the service
ExecStart=/usr/bin/sleep infinity # placeholder — put your real program path here (must exist; verify checks)
Restart=on-failure # restart on non-zero exit / signal, not on clean exit
User=www-data # run unprivileged, not as root (use your app's own user)
[Install]
WantedBy=multi-user.target # "enable" hooks this unit into the normal multi-user boot
systemd-analyze verify ./myapp.service # this exact file passes verify with no warnings
