【Linux】 サービス管理 ~ service/systemctl ~

■ はじめに

Linuxのサービス管理(service・chkconfig / systemd (systemctl))について
まとめる

目次

【0】サービス管理
 1)CentOS6以前
 2)CentOS7以降
【1】service / chkconfigコマンド
 1)サービス起動・停止
 2)サービス自動起動
 3)サービスリストの確認
【2】systemctl コマンド
 1)サービス起動・停止
 2)サービス自動起動
【3】その他

【0】サービス管理

1)CentOS6以前

* service・chkconfigコマンドを利用

2)CentOS7以降

* systemctl コマンドを利用

【1】service / chkconfigコマンド

1)サービス起動・停止

[1-1] サービスの起動

# service <サービス名> start
sudo service docker start

[1-2] サービスの停止

# service <サービス名> stop
sudo service docker stop

[1-3] サービスの再起動

# service サービス名 restart
sudo service docker restart

2)サービス自動起動

[2-1] サービスの自動起動設定

# chkconfig サービス名 on
sudo chkconfig docker on

[2-2] サービスの自動起動解除

chkconfig サービス名 off
sudo chkconfig docker off

3)サービスリストの確認

sudo service --status-all

https://dk521123.hatenablog.com/entry/2020/05/24/000000

でトラブルシュートした際に

http://var.blog.jp/archives/85880603.html

で知った。
サービスリストに登録されているかどうかが分かり
トラブルシュート時に役に立つ。

【2】systemctl コマンド

1)サービス起動・停止

[1-1] サービスの起動

systemctl start サービス名.service

[1-2] サービスの停止

systemctl stop サービス名.service

[1-3] サービスの再起動

systemctl restart サービス名.service

2)サービス自動起動

[2-0] サービスの自動起動確認

systemctl is-enabled サービス名.service

[2-1] サービスの自動起動設定

systemctl enable サービス名.service

[2-2] サービスの自動起動解除

systemctl disable サービス名.service

【3】その他

[3-1] サービスの確認

systemctl list-units --type=service

[3-2] 設定ファイル変更をsystemdに反映させる

systemctl daemon-reload

参考文献

http://www.server-memo.net/centos-settings/centos7/service-start.html
http://www.server-memo.net/centos-settings/centos7/systemctl-enable.html
構文などが分かる
https://wiki.archlinuxjp.org/index.php/Systemd

関連記事

Amazon ECR でのトラブルシューティング
https://dk521123.hatenablog.com/entry/2020/05/24/000000
systemd で独自サービスを立ち上げる
https://dk521123.hatenablog.com/entry/2017/07/30/100204
Linuxの起動について ~ プロセス / デーモン ~
Linux(仮想環境) を構築する ~CentOS編~
Tomcatをデーモンとして起動するには ~ /etc/init.d / Debian編~
Tomcatをデーモンとして起動するには ~ /etc/init.d / openSUSE編~
Linuxでの開発用SMTPサーバー [2] ~ MailCatcher編 ~
AWS(Amazon Web Services) ~ 入門編 / EC2作成 ~