Loading...
Cheat sheet
systemctl, journalctl, unit files, timers, targets, and overrides.
# Start / stop / restart a service
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
# Reload config without restart
systemctl reload nginx
# Enable / disable at boot
systemctl enable nginx
systemctl disable nginx
# Enable and start in one step
systemctl enable --now nginx
# Check service status
systemctl status nginx
# Check if active / enabled
systemctl is-active nginx
systemctl is-enabled nginx
# List all failed units
systemctl --failed# All logs for a service
journalctl -u nginx
# Follow live logs
journalctl -u nginx -f
# Last 100 lines
journalctl -u nginx -n 100
# Logs since last boot
journalctl -u nginx -b
# Logs in time range
journalctl -u nginx \
--since "2026-05-01 00:00:00" \
--until "2026-05-01 12:00:00"
# Kernel messages
journalctl -k
# Priority filter (err, warning, info, debug)
journalctl -u nginx -p err
# Output as JSON
journalctl -u nginx -o json | jq '.'
# Disk usage of journal
journalctl --disk-usage# /etc/systemd/system/my-app.service
[Unit]
Description=My Application
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=myapp
WorkingDirectory=/opt/my-app
ExecStart=/opt/my-app/bin/server --port 8080
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s
StandardOutput=journal
StandardError=journal
Environment=NODE_ENV=production
EnvironmentFile=/etc/my-app/env
[Install]
WantedBy=multi-user.target# /etc/systemd/system/cleanup.timer
[Unit]
Description=Run cleanup daily
[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
---
# /etc/systemd/system/cleanup.service
[Unit]
Description=Cleanup job
[Service]
Type=oneshot
ExecStart=/usr/local/bin/cleanup.sh
---
# Enable and start timer
systemctl enable --now cleanup.timer
# List all timers
systemctl list-timers# List all active targets
systemctl list-units --type=target
# Get default boot target
systemctl get-default
# Set default boot target
systemctl set-default multi-user.target
# Common targets:
# multi-user.target — CLI, no GUI (default for servers)
# graphical.target — multi-user + GUI
# rescue.target — single user, minimal services
# network.target — networking is up
# Show dependency tree for a unit
systemctl list-dependencies nginx
# Show reverse dependencies (what depends on it)
systemctl list-dependencies --reverse nginx# Reload systemd after editing unit files
systemctl daemon-reload
# Edit a unit file (creates override)
systemctl edit nginx
# Edit the full unit file
systemctl edit --full nginx
# Show effective unit (with overrides applied)
systemctl cat nginx
# Revert override
systemctl revert nginx
# Mask a unit (prevent start)
systemctl mask nginx
# Unmask
systemctl unmask nginx