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 / restartAct on the service now, without changing boot behaviour.
reloadRe-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-reloadRequired after you edit a .service file, before restarting it.
list-units --failedEverything that failed to start.
--userAct on your own user units instead of the system ones.

sudo systemctl restart nginx

Restart the web server.

systemctl status sshd --no-pager

Print the state and recent log lines without opening a pager.

sudo systemctl enable --now docker

Start 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