systemd

26 commands

26 shown

Enable and start service Enable at boot and start immediately in one command systemctl enable --now myapp.service #systemd Show failed units List all units that are in a failed state systemctl list-units --state=failed #systemd#debug Reload unit file after edit Reload unit definitions and restart the service systemctl daemon-reload && systemctl restart myapp.service #systemd Override unit with drop-in Create /etc/systemd/system/myapp.service.d/override.conf with partial overrides systemctl edit myapp.service #systemd Show unit file content Print the full unit file including drop-ins systemctl cat myapp.service #systemd#debug Analyze boot time Show top 20 units by initialization time systemd-analyze blame | head -20 #systemd#performance#monitoring Draw boot dependency graph Render full boot dependency graph as SVG systemd-analyze dot --require | dot -Tsvg > boot.svg && open boot.svg #systemd#debug 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 #systemd 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 #systemd 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 #systemd Set memory limit on service Apply cgroup limits without editing unit file systemctl set-property myapp.service MemoryMax=512M CPUQuota=50% #systemd#performance Show service resource usage Current memory, CPU, and task counts from cgroup systemctl status myapp.service | grep -E 'Memory:|CPU:|Tasks:' #systemd#monitoring List all socket units All socket-activated units and their state systemctl list-units --type=socket --all #systemd#network Mask a service Prevent a service from being started by anything systemctl mask snapd.service #systemd#security Show environment of service Print environment variables injected into the service systemctl show myapp.service -p Environment #systemd#debug Boot critical chain Show the serialized dependency chain that actually delays boot; more honest than blame systemd-analyze critical-chain <unit> #systemd#performance#troubleshooting Boot timeline SVG Render full parallel boot timeline as an SVG to spot serialized stalls visually systemd-analyze plot > boot.svg #systemd#performance#observability 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 #systemd#gitops#troubleshooting Reload unit files Reload unit files after editing; note: required after manual edits or systemctl warns of stale config systemctl daemon-reload #systemd#troubleshooting 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> #systemd#security#troubleshooting 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 #systemd#debug#troubleshooting 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> #systemd#monitoring#performance 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 #systemd#troubleshooting#debug 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 #systemd#ci#troubleshooting 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% #systemd#performance#troubleshooting Pending jobs queue Show in-flight start/stop jobs to diagnose a hung boot or a unit stuck activating systemctl list-jobs #systemd#debug#troubleshooting
no commands match