LoginSignup
9
10

More than 5 years have passed since last update.

CentOS7でnginxのコンフィグテスト、サービス再起動、エラーログ表示をワンライナーで

Last updated at Posted at 2016-03-29

CentOS7から起動スクリプトが変更になったようで戸惑いました。

Fedora15 から一部のサービス、CentOS7 より systemd services で管理される様になりました。 この事により今まで久し馴染んできたコマンド(service xxx start や chkconfig xxx on)では実行や停止、自動起動の設定などができないサービスがあります。(例えば dhcpd サービスなど)
これらのスクリプトは /lib/systemd/system 配下に存在し、systemd services のコマンド systemctl で制御する様になっています。
http://kajuhome.com/service_list.shtml

systemctlというコマンドを使うようになったようです。
サービス系のconfのエラーなどもsystemctlを利用するようですね。

良く忘れるのでメモです。

nginxの場合だと以下のようにするとconfエラーを表示できます。

$ sudo systemctl restart nginx.service || sudo systemctl status nginx.service -l 

nginx -t をすると尚良しかと。

$ sudo sh -c 'nginx -t && systemctl restart nginx.service || systemctl status nginx.service -l'
  1. root権限
  2. コンフィグテスト
  3. 2が通ればサービス再起動(コンフィグの読み直し)
  4. 3で失敗した場合にエラーログの表示

となります。

9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10