Skip to main content
๐Ÿš€ Claude Code Bootcamp โ€” May 30 5 hours from prompting to production. Build 10 real-world projects with AI-assisted development. Register Now
systemd Cheat Sheet 2026: Service Management on Linux
DevOps

systemd Cheat Sheet 2026: Service Management on Linux

systemd cheat sheet for Linux service management. systemctl start/stop/enable, unit file creation, journalctl log queries, timers, and service troubleshooting.

LB
Luca Berton
ยท 1 min read

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 installed

Custom 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 myapp

Journalctl (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 paging

Timers (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 --all

System 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 path

Tips and Tricks

  • Use systemctl edit nginx to create override files without modifying original unit
  • Use Type=notify for services that signal readiness via sd_notify
  • Use WantedBy=multi-user.target for server services, graphical.target for desktop
  • Use journalctl -f -u nginx as a replacement for tail -f on service logs
  • Use systemd timers instead of cron for better logging and dependency management

Free 30-min AI & Cloud consultation

Book Now