A quick reference for systemd โ Linux service and system management. Bookmark this page.
Service Management
# Start/stop/restart
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx # Reload config without restart
# Enable/disable at boot
sudo systemctl enable nginx
sudo systemctl disable nginx
sudo systemctl enable --now nginx # Enable AND start
# Status
systemctl status nginx
systemctl is-active nginx
systemctl is-enabled nginx
systemctl is-failed nginx
# List services
systemctl list-units --type=service
systemctl list-units --type=service --state=running
systemctl list-units --type=service --state=failed
systemctl list-unit-files --type=service # All installedCustom Service Units
# /etc/systemd/system/myapp.service
[Unit]
Description=My Application
Documentation=https://example.com/docs
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=appuser
Group=appgroup
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/bin/server --config /etc/myapp/config.yaml
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
Environment=NODE_ENV=production
EnvironmentFile=/etc/myapp/env
# Security hardening
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
ReadWritePaths=/var/lib/myapp
[Install]
WantedBy=multi-user.target# After creating/modifying unit file
sudo systemctl daemon-reload
sudo systemctl enable --now myappJournalctl (Logging)
# View all logs
journalctl
# Logs for a specific service
journalctl -u nginx
journalctl -u nginx -f # Follow (live tail)
journalctl -u nginx --since today
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx --since "2026-04-12 10:00" --until "2026-04-12 12:00"
# Logs by priority
journalctl -p err # Errors and above
journalctl -p warning -u nginx
# Boot logs
journalctl -b # Current boot
journalctl -b -1 # Previous boot
journalctl --list-boots # List all boots
# Disk usage
journalctl --disk-usage
sudo journalctl --vacuum-size=500M # Clean up to 500MB
sudo journalctl --vacuum-time=30d # Keep last 30 days
# Output formats
journalctl -u nginx -o json-pretty
journalctl -u nginx -o short-precise
journalctl -u nginx --no-pager # Disable pagingTimers (Cron Replacement)
# /etc/systemd/system/backup.timer
[Unit]
Description=Daily backup timer
[Timer]
OnCalendar=*-*-* 02:00:00 # Daily at 2 AM
Persistent=true # Run if missed
RandomizedDelaySec=300 # Random delay up to 5 min
[Install]
WantedBy=timers.target
# /etc/systemd/system/backup.service
[Unit]
Description=Daily backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh# Enable timer
sudo systemctl enable --now backup.timer
# List timers
systemctl list-timers
systemctl list-timers --allSystem Management
# Reboot/shutdown
sudo systemctl reboot
sudo systemctl poweroff
sudo systemctl halt
# Default target (runlevel)
systemctl get-default
sudo systemctl set-default multi-user.target # No GUI
sudo systemctl set-default graphical.target # With GUI
# Analyze boot time
systemd-analyze
systemd-analyze blame # Per-unit startup times
systemd-analyze critical-chain # Critical pathTips and Tricks
- Use
systemctl edit nginxto create override files without modifying original unit - Use
Type=notifyfor services that signal readiness via sd_notify - Use
WantedBy=multi-user.targetfor server services,graphical.targetfor desktop - Use
journalctl -f -u nginxas a replacement fortail -fon service logs - Use systemd timers instead of cron for better logging and dependency management