【Linux】systemd 〜 systemctlコマンド 〜

◾️はじめに

今更だが、調査でsystemctlコマンドを使ったのでメモ

目次

【1】サービス起動・停止
 1)サービスの起動
 2)サービスの停止
 3)サービスの再起動
【2】サービス自動起動
 1)サービスの自動起動確認
 2)サービスの自動起動設定
 3)サービスの自動起動解除
【3】その他
 1)サービス一覧表示
 2)設定ファイル変更をsystemdに反映させる

【1】サービス起動・停止

1)サービスの起動

systemctl start サービス名.service

2)サービスの停止

systemctl stop サービス名.service

3)サービスの再起動

systemctl restart サービス名.service

【2】サービス自動起動

1)サービスの自動起動確認

systemctl is-enabled サービス名.service

2)サービスの自動起動設定

systemctl enable サービス名.service

3)サービスの自動起動解除

systemctl disable サービス名.service

【3】その他

1)サービス一覧表示

systemctl list-units --type=service
# or
systemctl list-units -t service

https://tex2e.github.io/blog/linux/systemctl-list-services

補足:grepとの併用

# 有効化しているサービス一覧
systemctl list-unit-files -t service | grep enabled

# 無効化しているサービス一覧
systemctl list-unit-files -t service | grep disabled

# サービス"xxxxx"があるかどうか
systemctl list-unit-files -t service | grep xxxxx

2)設定ファイル変更をsystemdに反映させる

systemctl daemon-reload

関連記事

サービス管理 ~ service ~
https://dk521123.hatenablog.com/entry/2016/07/26/223003
systemd 〜 入門編 〜
https://dk521123.hatenablog.com/entry/2017/07/30/100204
systemd 〜 journalctl 〜
https://dk521123.hatenablog.com/entry/2025/01/01/012049