CentOS7 や Amazon Linux 2 での systemctl や service の早見表。
root や sudo で実行する必要あり。
基本的に sudo を基本に書いていきます。
systemclt と service は基本的に反対
起動
$ sudo systemctl start [UNIT]
$ sudo service [UNIT] start
例
$ sudo systemctl start nginx
$ sudo service nginx start
設定反映 (config 読み込み)
設定の適用なので、サービスの瞬断は無いはず。
$ sudo systemctl reload [UNIT]
$ sudo service [UNIT] reload
例
$ sudo systemctl reload nginx
$ sudo service nginx reload
再起動
サービスの瞬断あり。
$ sudo systemctl restart [UNIT]
$ sudo service [UNIT] restart
例
$ sudo systemctl reload nginx
$ sudo service nginx reload
停止
$ sudo systemctl stop [UNIT]
$ sudo service [UNIT] stop
例
$ sudo systemctl stop nginx
$ sudo service nginx stop
ステータス表示
$ sudo systemctl stop [UNIT]
$ sudo service [UNIT] stop
例
$ sudo systemctl status nginx
$ sudo service nginx status
サービス自動起動設定
サーバー起動時に、自動的にサービスを立ち上げるかどうかの設定。
有効化
$ sudo systemctl enable [UNIT]
$ sudo service [UNIT] enable
例
$ sudo systemctl enable nginx
$ sudo service nginx enable
サービス自動起動設定
無効化
$ sudo systemctl enable [UNIT]
$ sudo service [UNIT] enable
例
$ sudo systemctl enable nginx
$ sudo service nginx enable
サービス一覧表示
$ sudo systemctl list-unit-files --type=service
設定ファイルの再読み込み
$ sudo systemctl daemon-reload