Systemd Cheatsheet - Systemd Service Management Command Reference

systemd deserves a pass on its own because on modern Linux distributions it unifies four things that people still split across three parallel toolchains: service management, log querying, scheduling and resource limits. Filtering journalctl by unit, by time window and by priority is far more precise than grepping files in /var/log, especially when a service dies immediately after start - combining --since with -p err narrows the output to this boot's errors. This sheet covers service control, status inspection, journal troubleshooting, targets and runlevels, timers, unit configuration and resource control, and failure analysis. Which group to open depends on the symptom: start and stop for the first, "where do the logs live" for the third, "how do I cap CPU and memory" for the sixth. The timer group is the replacement for crontab, and it wins on execution logs, dependency ordering and inspectable failures.

SysOps·47 commands·Last updated 2026-07-21
systemdsystemctljournalctlServices

Typical Use Case

For operators and back-end engineers managing long-running services on a Linux server. systemd replaces SysVinit scripts by unifying service state, boot enablement, logs, scheduled tasks and resource limits under one set of commands and one configuration model. Its real value is a fixed troubleshooting path: status for state, journalctl for logs, cat for configuration, daemon-reload to pick up changes. This sheet covers those four steps plus timers and resource limits, which together resolve almost every configuration problem.

Service Management 8

systemctl start nginx
Start the service into the running state; does not add it to boot-enable, so it goes away on reboot
systemctl stop nginx
Stop the running service, running its ExecStop before exit; does not touch whether it is enabled at boot
systemctl restart nginx
Stop then start again; drops active connections, so prefer reload when the process holds persistent sessions
systemctl reload nginx
Gracefully reload config without dropping connections; not all services support reload
systemctl enable nginx
Enable the service to start at boot; add --now to also start it immediately
systemctl disable nginx
Disable the service from starting at boot
systemctl enable --now nginx
Enable at boot and start immediately
systemctl mask nginx
Fully disable a service so it cannot be started manually or pulled in by other units

Status 7

systemctl status nginx
Show service state and recent logs (most common)
systemctl is-enabled nginx
Show whether the service is enabled at boot
systemctl is-active nginx
Show whether the service is currently running
systemctl is-failed nginx
Check whether the service is in a failed state
systemctl list-units --type=service
List all loaded service units
systemctl list-unit-files --type=service
List all installed service files and their boot-enable state
systemctl list-units --failed
List failed services to troubleshoot startup errors

journalctl 8

journalctl -u nginx
Show logs for the specified service
journalctl -u nginx -f
Follow the service's logs in real time
journalctl --since "10 min ago" -u nginx
Show logs from the last 10 minutes
journalctl --since today --until "1 hour ago"
Filter logs by a time range
journalctl -p err -b
Show logs at error level and above since boot
journalctl -u nginx -n 100 --no-pager
Show the last 100 log lines without paging
journalctl --disk-usage
Show how much disk space journal logs use
journalctl --vacuum-size=100M
Vacuum logs, keeping only the most recent 100 MB

Targets & Runlevels 6

systemctl get-default
Show the default boot target (equivalent to the runlevel)
systemctl set-default multi-user.target
Set the default to multi-user (command-line) mode
systemctl set-default graphical.target
Set the default to graphical desktop mode
systemctl isolate multi-user.target
Switch to multi-user mode immediately (equivalent to init 3)
systemctl rescue
Enter rescue mode (requires root; stops non-essential services)
systemctl list-units --type=target
List all currently active targets

Timers 6

systemctl list-timers
List all scheduled timers (replaces crontab -l)
systemctl list-timers --all
List all timers, including inactive ones
systemctl status <timer>
Show a timer's state and next execution time
systemctl start <timer> && systemctl enable <timer>
Enable a timer and start it at boot
systemctl cat <timer>
Show the timer unit file contents
journalctl -u <timer>
Show logs of the service triggered by the timer

Service Config & Resource Control 6

systemctl cat nginx
Show the service's unit file contents
systemctl edit nginx
Edit a service override config, stored in override.conf
systemctl edit --full nginx
Edit the full unit file (not as an override)
systemctl daemon-reload
Reload systemd configuration after editing unit files
systemctl set-property nginx CPUQuota=50%
Limit the service to at most 50% CPU
systemctl set-property nginx MemoryMax=512M
Cap the service's memory at 512 MB

Troubleshooting & Analysis 6

systemctl --failed
Quickly show all failed services
systemctl reset-failed nginx
Clear the failed state of a service
systemd-analyze time
Show total boot time
systemd-analyze blame
List each service's startup time, sorted by duration
systemd-analyze critical-chain nginx
Show the startup dependency chain for a service
systemctl daemon-reload
Required after editing unit files, otherwise config won't take effect

Parameter matrix

ParameterEffectExample
enable --now设置开机自启并立即启动(一步完成两件事)systemctl enable --now nginx
reload vs restart平滑重载不断连接 / 重启进程会断连接systemctl reload nginx
mask vs disable彻底禁用(无法被间接拉起)/ 仅取消自启systemctl mask nginx
status查看状态、最近日志与 PIDsystemctl status nginx
is-active / is-enabled脚本友好:运行中 / 已自启的退出码systemctl is-active nginx
--failed列出所有失败的服务systemctl --failed
journalctl -u -f按单元过滤并实时跟踪journalctl -u nginx -f
--since / --until按时间窗口过滤日志journalctl --since "10 min ago" -u nginx
-p err -b本次开机以来的 error 及以上journalctl -p err -b
--vacuum-size清理日志只保留指定大小journalctl --vacuum-size=100M
list-timers查看定时任务,替代 crontab -lsystemctl list-timers
daemon-reload改完单元文件后重新加载(必做)systemctl daemon-reload
set-property运行时限制 CPU 与内存systemctl set-property nginx MemoryMax=512M
systemd-analyze blame按耗时排序列出各服务启动时间systemd-analyze blame

Common pitfalls

Symptom改了单元文件,systemctl restart 后配置依然没生效。

Cause修改单元文件后 systemd 不会自动重新读取配置。

Fix执行 systemctl daemon-reload 再 restart;systemctl edit 生成的 override.conf 同理。

Symptom服务反复启动失败,status 显示 Restarting 循环。

CauseExecStart 路径不存在、权限不足或依赖服务未就绪,systemd 按 Restart 策略反复重试。

Fixjournalctl -u <服务> -n 100 --no-pager 看真实报错;用 systemctl cat 核对 ExecStart 路径。

Symptom服务已经 enable,但重启机器后没有自启。

Causeenable 只写了自启链接,而服务被 mask 过,mask 优先级高于 enable。

Fixsystemctl is-enabled <服务> 确认真实状态;如为 masked 先 systemctl unmask。

Symptomrestart 后客户端全部连接断开,业务出现瞬时错误。

Causerestart 会终止旧进程再启动,断开了所有已建立连接。

Fix支持 reload 的服务(nginx)改用 systemctl reload 做平滑重载,不断连接。

Symptom磁盘被 journal 日志占满。

Causejournal 默认轮转但上限可能很大,长期无人清理。

Fixjournalctl --disk-usage 查看占用,journalctl --vacuum-size=100M 清理;并可配置 SystemMaxUse。

Symptom启动变慢,journalctl 报启动超时。

Cause某个服务单元配置了过长的 TimeoutStartSec,依赖服务慢时会卡住整体启动。

Fixsystemd-analyze blame 找出耗时最长的单元,systemd-analyze critical-chain 看依赖链后针对性处理。

Symptom手动 stop 服务后,过一会又被其他服务拉起来了。

Cause该服务被另一个单元(如 target 或 Requires 依赖)作为依赖启动。

Fixsystemctl list-units --type=service 查反向依赖;确需彻底停用时用 systemctl mask。

Troubleshooting

  1. 1服务不工作时的标准四步

    systemctl status nginx && journalctl -u nginx -n 100 --no-pager

    status 看状态与最近日志,journalctl 拉完整历史;这两步能解决多数启动失败。

  2. 2确认配置是否真的被读取

    systemctl cat nginx

    同时列出主单元文件与 override 片段,排查配置被覆盖时必看。

  3. 3改完单元文件让配置生效

    systemctl daemon-reload && systemctl restart nginx

    daemon-reload 漏掉是最常见的「改了没反应」原因。

  4. 4实时盯日志配合改配置

    journalctl -u nginx -f

    另开终端改配置并 reload,错误是否消失一眼可见。

  5. 5脚本里判断服务状态

    systemctl is-active nginx || systemctl restart nginx

    is-active 以退出码表达状态,适合写进健康检查脚本。

Command Examples

Status plus recent logs when a service will not start

systemctl status nginx

status 把加载状态、运行状态、启动时间和主进程都打出来,是排查第一步。要跟实时日志就在同一命令加 -f 或改用 journalctl -u nginx -f。

Output

● nginx.service - A high performance web server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
   Active: active (running) since Mon 2026-09-29 10:12:03 CST; 2 days ago
  Process: 1420 ExecStart=/usr/sbin/nginx /etc/nginx/nginx.conf

Errors from the last 10 minutes only

journalctl -p err --since "10 min ago" -u nginx --no-pager

--since 支持相对时间,"10 min ago" 比写绝对时间省事。加 --no-pager 防止输出进 less 而在脚本里卡住。

Output

Sep 30 14:02:11 host nginx[1420]: [error] 1420#1420: *3 open() "/usr/share/nginx/html/x" failed (2: No such file or directory)
Sep 30 14:02:11 host nginx[1420]: [error] 1420#1420: *3 connect() failed (111: Connection refused)

Find out why a service starts slowly

systemd-analyze blame | head

blame 按耗时排序列出各服务,critical-chain <unit> 则展开某个服务的依赖链。优化启动时间先看排在最前面的那几个。

Output

  1.204s NetworkManager-wait-online.service
  842ms docker.service
  231ms nginx.service
  118ms systemd-logind.service

Common Pitfalls

  • Editing a unit file without systemctl daemon-reload leaves systemd using the in-memory version, so nothing changes.
  • restart drops connections; prefer reload for a smooth switch, though not every service implements it.
  • enable only configures boot-time start and start only affects the current session; use enable --now for both.
  • systemctl edit writes an override.conf on top of the original — roll back by deleting that override.
  • Non-critical services are stopped in rescue or isolate targets; confirm which target you are in before running this on production.

Tips

  • reload gracefully reloads config without dropping connections, while restart recreates the process. Not all services support reload — nginx does.
  • journal logs rotate by default; if --disk-usage is too large, clean up with journalctl --vacuum-size=100M.
  • Timers are more controllable than crontab: you can see execution logs in journalctl and they support dependency relationships.
  • You must run systemctl daemon-reload after editing a unit file, otherwise systemd won't read the new config.
  • systemctl edit creates an override.conf snippet that doesn't modify the original unit file — safer.
  • mask is more thorough than disable: a masked service cannot be started manually or indirectly. Mask it before uninstalling a service.

FAQ

What is the difference between systemctl start and enable?

start only launches the service in the current session and it will not come back after a reboot; enable configures it to start at boot but does not start it now. They are independent, which is why systemctl enable --now nginx is the idiom for both. To check state, use systemctl is-enabled nginx and systemctl is-active nginx.

When can I not swap restart for reload?

reload applies new configuration without dropping existing connections and suits services like Nginx that support hot reloading; restart interrupts connections and starts over. Use restart only when the unit does not implement reload, or the change touches something that cannot be hot-swapped such as a listening port. Also note a syntax error will simply prevent the service from starting on restart — for Nginx, validate with nginx -t first.

Where do I look when a service will not start?

systemctl status nginx prints the state plus the last few log lines and is the one you will use most; journalctl -u nginx gives the full history and -f follows it live. Bound the window with journalctl --since "10 min ago" -u nginx, or restrict to error level and up with journalctl -p err -b. For a service that keeps restarting, systemctl show nginx explains why it exited.

Why does my systemd unit file change have no effect?

You must run systemctl daemon-reload so systemd re-reads configuration, then restart the service. Editing the file alone leaves systemd using the in-memory version. Prefer systemctl edit nginx for changes — it writes an override.conf instead of touching the original, so rolling back just means deleting that override.

How do I replace crontab with systemd timers?

Use a systemd timer — better suited when you need precise control, want the task to depend on service state, or want logs. systemctl list-timers shows every timer and its next run; after writing a matching .service and .timer pair, enable it with systemctl enable --now <timer>. Output goes to journalctl -u <service>, which is far easier to debug than cron mail.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us