systemctl の使い方

サービスの起動・停止・自動起動

書き方

systemctl start|stop|restart|reload|status サービス
systemctl enable|disable [--now] サービス
systemctl mask|unmask サービス
systemctl is-active|is-enabled サービス
systemctl list-units --type=service [--failed]
systemctl list-unit-files --state=enabled
systemctl reboot / poweroff(reboot・shutdown -r now と同じ)
systemctl default(緊急モードから起動の続き)

start は今すぐ起動、enable は再起動後も自動で起動。enable --now で両方。mask すると手で start しても起動できなくなります。再起動すると、今だけの変更(mount・swapon・setenforce・firewall-cmd の runtime)は消えます。操作には sudo が必要です。

よく使うオプション

オプション意味
start / stop / restart起動する / 止める / 止めて起動し直す
reload止めずに設定を読み直す(対応しているサービスだけ)
status動いているか、最近のログ
enable / disable起動したときに自動で動かす / 動かさない
--nowenable と同時に start(disable なら stop)もする
is-active / is-enabled動いているか / 自動で動くかだけを答える
list-units --failed失敗したサービスの一覧
daemon-reloadユニットのファイルを書き換えたあとに読み直す

例

$ systemctl status sshd● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Fri 2026-11-06 09:12:03 JST; 1 day ago
   Main PID: 1123 (sshd)

sshd が動いているか確かめます。Active: active (running) なら動いています。

$ sudo systemctl restart php-fpm

php-fpm を止めて起動し直します。設定を変えたあとによく使います。

$ systemctl is-enabled crondenabled

crond がサーバーの起動と一緒に動く設定かを答えます。

$ systemctl list-units --type=service --failed

起動に失敗したサービスだけを一覧にします。障害のときに最初に見る場所の 1 つです。

よくある間違い・注意

  • start は今だけ、enable は次の起動から自動で、という別の働きです。両方したいときは enable --now を使います。
  • status の出力が長いと less で止まります。q で抜けます。
  • ユニットのファイルを書き換えたら、systemctl daemon-reload をしないと読み込まれません。

実際に打って練習する

Linux レベル1 コースの Lv56「番人を起こす systemctl」で覚えます(第4章 サーバーの守り手(パッケージとサービス))。ブラウザの中のシミュレーターで、本物と同じように打って確かめられます。

Lv1〜16 は、登録不要・無料で遊べます(それより先はブロンズ以上のプランで遊べます)。

Linux コマンド一覧(LinuC レベル1 の範囲)へ戻る