systemd
26 commands
26 shown
Enable and start service
Enable at boot and start immediately in one command
systemctl enable --now myapp.service
Show failed units
List all units that are in a failed state
systemctl list-units --state=failed
Reload unit file after edit
Reload unit definitions and restart the service
systemctl daemon-reload && systemctl restart myapp.service
Override unit with drop-in
Create /etc/systemd/system/myapp.service.d/override.conf with partial overrides
systemctl edit myapp.service
Show unit file content
Print the full unit file including drop-ins
systemctl cat myapp.service
Analyze boot time
Show top 20 units by initialization time
systemd-analyze blame | head -20
Draw boot dependency graph
Render full boot dependency graph as SVG
systemd-analyze dot --require | dot -Tsvg > boot.svg && open boot.svg
Create a simple service unit
Minimal systemd service unit template
cat > /etc/systemd/system/myapp.service <<EOF
[Unit]
Description=My App
After=network.target
[Service]
ExecStart=/usr/bin/myapp
Restart=always
RestartSec=5
User=appuser
[Install]
WantedBy=multi-user.target
EOF
Run one-shot as another user
Run a transient one-shot unit under a specific user
systemd-run --uid=1000 --gid=1000 --wait /usr/bin/myapp --task
Create systemd timer
Replacement for cron with Persistent=true for missed runs
cat > /etc/systemd/system/backup.timer <<EOF
[Unit]
Description=Daily backup
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF
Set memory limit on service
Apply cgroup limits without editing unit file
systemctl set-property myapp.service MemoryMax=512M CPUQuota=50%
Show service resource usage
Current memory, CPU, and task counts from cgroup
systemctl status myapp.service | grep -E 'Memory:|CPU:|Tasks:'
List all socket units
All socket-activated units and their state
systemctl list-units --type=socket --all
Mask a service
Prevent a service from being started by anything
systemctl mask snapd.service
Show environment of service
Print environment variables injected into the service
systemctl show myapp.service -p Environment
Boot critical chain
Show the serialized dependency chain that actually delays boot; more honest than blame
systemd-analyze critical-chain <unit>
Boot timeline SVG
Render full parallel boot timeline as an SVG to spot serialized stalls visually
systemd-analyze plot > boot.svg
Drop-in override
Patch a unit via drop-in without touching the vendor file; use --full to fork the whole unit
systemctl edit <unit> # writes /etc/systemd/system/<unit>.d/override.conf
Reload unit files
Reload unit files after editing; note: required after manual edits or systemctl warns of stale config
systemctl daemon-reload
Mask a unit
Mask symlinks a unit to /dev/null so it cannot start even as a dependency; stronger than disable
systemctl mask <unit> && systemctl unmask <unit>
Recursive dependency tree
Walk the full Wants/Requires tree to debug why a service pulls in others; --reverse for who needs it
systemctl list-dependencies <unit> --all
Live memory of a unit
Read live cgroup metrics straight from systemd without ps; MemoryCurrent is the accounted RSS
systemctl show -p MainPID,MemoryCurrent,TasksCurrent <unit>
Clear failed state
Reset failed counters so units can restart past StartLimitBurst, then list what is still failed
systemctl reset-failed && systemctl list-units --state=failed
Transient one-shot timer
Spin up a throwaway timer+service without writing unit files; great for ad-hoc scheduled jobs
systemd-run --on-calendar='*-*-* 03:00:00' --unit=backup /usr/local/bin/backup.sh
Runtime resource cap
Apply cgroup limits live without restart; --runtime keeps them volatile (gone on reboot)
systemctl set-property --runtime <unit> MemoryMax=512M CPUQuota=50%
Pending jobs queue
Show in-flight start/stop jobs to diagnose a hung boot or a unit stuck activating
systemctl list-jobs
no commands match