On this page
systemd Operations Manual
systemd is the init system and service manager for the Linux user space. Understanding unit types (service/timer/socket/mount), dependencies, the logging system, and the override mechanism is fundamental for operations.
Process viewing: btm (bottom, a replacement for top — CPU/memory/disk/temperature TUI), procs (a replacement for ps — colored, auto column width, process tree)
Check Status
# Check the current status of a unit, including the last 10 lines of logs, cgroup tree, and main PID
# Active: active (running) since ... — Running
# Active: inactive (dead) — Not running
# Active: failed — Startup failed (check exit code)
# List all units, filtered by status
# Check if a unit is enabled (starts on boot)
# View the dependency tree of a unit
# View the unit file content (including all drop-ins)
# List all timers and their next trigger times
Management
# Start/Stop/Restart
# Difference: reload does not interrupt connections, restart does
# If the service does not support reload, this command will fail
# mask vs disable: after disable, you can still manually start; after mask, even manual start is rejected
# Must run after modifying unit files
# Clear failed status (otherwise status will always show failed)
User-level Services
# User services are independent of system services: ~/.config/systemd/user/
# User services stop by default after logout (unless lingering is enabled)
# Enable lingering (service continues running after logout):
# Suitable for: rathole-watchdog, local llama-server, and other user services that need to run persistently
Timer
Timers trigger the corresponding service at a specified time (paired by name: .timer/.service):
# View timer definition
# Manually trigger (don't wait for next scheduled time)
# /etc/systemd/system/mytask.timer
[Timer]
# Trigger every 5min after last activation
OnUnitActiveSec=5min
# Trigger first time 2min after boot
OnBootSec=2min
# Random delay of 30s (avoid thundering herd when multiple machines run simultaneously)
RandomizedDelaySec=30
# Compensate for missed triggers (e.g., if the machine was asleep)
Persistent=true
[Install]
WantedBy=timers.target
# /etc/systemd/system/mytask.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/mytask.sh
User=myuser
Logs
|
# Space management
Override
To modify unit configuration, do not directly edit /usr/lib/systemd/system/ (as it will be overwritten by package management). Instead, create a drop-in:
# Open editor to create override
# → /etc/systemd/system/nginx.service.d/override.conf
# Or manually
Note: The first line ExecStart= must exist to clear the previous value. If not cleared first, the new ExecStart will be appended rather than replaced.
Troubleshooting
# Service fails to start
# Analyze startup bottlenecks
|
# Verify unit file
# A unit is masked, causing WantedBy to fail
|