systemctl
コマンドは、systemd によるサービス、ユニット、システム全体の状態を管理 するコマンドです。
サービスの起動・停止、再起動、ステータス確認、ブート時の自動起動設定など、Linux システム管理の中心的な役割を担います。
構文(Syntax)
systemctl [オプション] コマンド [ユニット]
主なオプション / サブコマンド一覧
サブコマンド | 説明 | 使用例 |
---|---|---|
start | サービスを開始 | sudo systemctl start nginx |
stop | サービスを停止 | sudo systemctl stop nginx |
restart | サービスを再起動 | sudo systemctl restart nginx |
reload | 設定ファイルを再読み込み(プロセス再起動せず) | sudo systemctl reload nginx |
status | サービスの状態を確認 | systemctl status nginx |
enable | サービスを自動起動に設定 | sudo systemctl enable nginx |
disable | 自動起動を無効化 | sudo systemctl disable nginx |
is-enabled | 自動起動の有効/無効を確認 | systemctl is-enabled nginx |
list-units | 現在有効なユニットを表示 | systemctl list-units |
list-unit-files | インストールされているユニットファイル一覧 | systemctl list-unit-files |
daemon-reload | ユニットファイルの変更を systemd に再読み込み | sudo systemctl daemon-reload |
poweroff | システムをシャットダウン | sudo systemctl poweroff |
reboot | システムを再起動 | sudo systemctl reboot |
suspend | サスペンド(スリープ) | sudo systemctl suspend |
hibernate | ハイバネート | sudo systemctl hibernate |
実行例
サービスを起動
sudo systemctl start ssh
サービスを停止
sudo systemctl stop ssh
サービスを再起動
sudo systemctl restart ssh
サービスの状態を確認
systemctl status ssh
出力例:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2025-08-21 13:10:12 JST; 5min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 1023 (sshd)
Tasks: 1 (limit: 4567)
Memory: 3.1M
CPU: 20ms
CGroup: /system.slice/ssh.service
└─1023 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
自動起動を有効化
sudo systemctl enable nginx
自動起動を無効化
sudo systemctl disable nginx
ユニットファイル一覧を確認
systemctl list-unit-files --type=service
システムを再起動
sudo systemctl reboot
エラー例(存在しないサービス)
systemctl status hogeservice
出力例:
Unit hogeservice.service could not be found.
関連コマンド
journalctl
: systemd のログを表示service
: 旧 SysVinit スタイルのサービス管理(systemctl へ内部的に転送されることが多い)shutdown
: システムの停止・再起動
備考
systemctl
は systemd 採用ディストリビューション(Ubuntu, Debian, CentOS, Fedora, Arch Linux など)で利用可能です。SysVinit
系(古い UNIX/Linux)ではsystemctl
は使えず、代わりにservice
や/etc/init.d/
スクリプトを使用します。- ユニットには
service
のほか、socket
,target
,mount
などさまざまな種類があります。 daemon-reload
はユニットファイルを編集した後に必ず実行する必要があります。
参考
- manページ: man7.org systemctl(1)
- systemd公式ドキュメント: https://www.freedesktop.org/wiki/Software/systemd/
コメント