systemctl
进程与系统
用法
systemctl <verb> <unit>启动、停止和查看 systemd 服务;`enable` 只决定开机行为,想现在也启动要用 `enable --now`,改过 unit 文件后必须 `daemon-reload`。
常用选项
| 选项 | 含义 |
|---|---|
| status <unit> | Whether it is running, its PID, and the last log lines. |
| start / stop / restart | Act on the service now, without changing boot behaviour. |
| reload | Re-read the config without dropping connections, if the service supports it. |
| enable --now <unit> | Start it now and also start it at every boot. |
| daemon-reload | Required after you edit a .service file, before restarting it. |
| list-units --failed | Everything that failed to start. |
| --user | Act on your own user units instead of the system ones. |
示例
sudo systemctl restart nginxRestart the web server.
systemctl status sshd --no-pagerPrint the state and recent log lines without opening a pager.
sudo systemctl enable --now dockerStart Docker and make it come back after a reboot.
看什么在跑、什么在吃机器。先弄清是什么,再决定杀不杀。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. systemctl 是做什么的?
启动、停止和查看 systemd 服务;`enable` 只决定开机行为,想现在也启动要用 `enable --now`,改过 unit 文件后必须 `daemon-reload`。
Q. 怎么写?
systemctl <verb> <unit> —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 7 个,完整列表在 man systemctl。这条命令属于进程与系统。
相关命令
man 手册: man systemctl