
UnsplashのTodd Diemerが撮影した写真
systemctlコマンドの使い方をよく忘れるのでメモです。
■状態確認
sudo systemctl status [サービス名]
例)sudo systemctl status mysql
■起動
sudo systemctl start [サービス名]
例)sudo systemctl start mysql
■停止
sudo systemctl stop [サービス名]
例)sudo systemctl stop mysql
■自動起動の設定状態確認
sudo systemctl is-enabled [サービス名]
例)sudo systemctl is-enabled mysql
■自動起動をON
sudo systemctl enable [サービス名]
例)sudo systemctl enable mysql
■自動起動をOFF
sudo systemctl disable [サービス名]
例)sudo systemctl disable mysql
サービス関係のコマンドとしてよく見る「systemctl」と「service」コマンドですが、
以下の違いのようです。
■systemctl
新しい(Ubuntu16.04以降)。
標準であり推奨されるコマンド。
■service
古い(Ubuntu16.04より前)。
今はsystemctlをラップして動作し、挙動はsystemctlとほとんど同じ
以下は同じ処理とのことなので、systemctlだけ覚えておけばいいようです。
sudo systemctl status apache2
sudo service apache2 status
以上です。