systemctl
プロセスとシステム
書き方
systemctl <verb> <unit>systemd のサービスを起こし、止め、状態を見ます。`enable` は起動時の設定だけなので今も動かすなら `enable --now`、ユニットファイルを直したあとは `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`、ユニットファイルを直したあとは `daemon-reload` が必要です。
Q. どう打ちますか。
systemctl <verb> <unit> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man systemctl にあります。このコマンドはプロセスとシステムの仲間です。
関連するコマンド
man ページ: man systemctl