systemd cheat sheet
systemd manages services on most modern Linux distributions.
Control a service
systemctl status <service>- State and last log lines
sudo systemctl start <service>- Start now
sudo systemctl stop <service>- Stop now
sudo systemctl restart <service>- Stop and start
sudo systemctl reload <service>- Reload config without restart (if supported)
sudo systemctl enable --now <service>- Start at boot and start now
sudo systemctl disable <service>- Do not start at boot
Inspect
systemctl list-units --type=service- Loaded services
systemctl --failed- Services that failed
systemctl is-active <service>- Prints active or inactive
systemctl cat <service>- Show the unit file
systemd-analyze blame- What slowed down boot
Logs with journalctl
journalctl -u <service>- Logs of one service
journalctl -u <service> -f- Follow in real time
journalctl -u <service> -n 50- Last 50 lines
journalctl --since "1 hour ago"- Recent entries
journalctl -p err -b- Errors since the last boot
journalctl --disk-usage- Space used by logs
A service unit (/etc/systemd/system/app.service)
[Unit] Description=My app After=network.target- Description and start order
[Service] ExecStart=/usr/bin/node /srv/app/index.js- Command to run (absolute path)
User=app WorkingDirectory=/srv/app- Run as a non-root user in a folder
Restart=on-failure RestartSec=5- Restart after a crash
Environment=NODE_ENV=production- Set a variable
[Install] WantedBy=multi-user.target- Needed for enable to work at boot
After editing units
sudo systemctl daemon-reload- Re-read unit files (always after changes)
sudo systemctl edit <service>- Create an override without touching the original
systemctl list-timers- Scheduled timers and next run
[Timer] OnCalendar=daily Persistent=true- Timer schedule, runs missed jobs after downtime
Learn it properly