CentOS用 Nginx起動スクリプト
上記ページにあるスクリプトを/etc/init.dに保存すればよいみたいですが、インスールした時の設定(prefixとか)によって少し変更しなければいけないかもです。
修正点
自分は./configureに何もオプションを付けなかったため、ファイルパスを修正。
## 5行目 ランレベルを35に # chkconfig: 35 85 15 ## 9行目。設定ファイルのパスを変更 # config: /usr/local/nginx/conf/nginx.conf ## 11行目。pidファイルのパスを変更 # pidfile: /usr/local/nginx/logs/nginx.pid ## 22行目 sbinの位置を修正 nginx="/usr/local/nginx/sbin/nginx" ## 25行目 設定ファイルのパスを変更 NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
実行権限を付与
作成した起動スクリプトに実行権限を付与します。
$ sudo chmod a+x /etc/init.d/nginx
登録
chkconfigコマンドで起動時に実行するスクリプトとして登録します。
$ sudo /sbin/chkconfig --add nginx $ sudo /sbin/chkconfig --list | grep nginx nginx 0:off 1:off 2:off 3:off 4:off 5:off 6:off # ランレベル3と5の時に起動スクリプトを実行 $ sudo /sbin/chkconfig --level 35 nginx on
実験
さくらVPSのコントロールパネルからサーバを停止&起動してみる。その後ログインして起動しているか確認。
$ ps aux | grep nginx root 1571 0.0 0.1 18692 576 ? Ss 00:26 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nginx 1572 0.0 0.2 19084 1088 ? S 00:26 0:00 nginx: worker process
よし!立ち上がってる!
思ったこと
- 起動スクリプトの仕組みが分かってよかった。
- コンパイル時にsbinや設定ファイルの位置を設定するべきだったような気がする。。。./configureのオプションを下記のように設定すれば公式サイトの起動スクリプトをほぼいじらなくてもOKな気がする。
$ sudo ./configure --user=nginx \ --group=nginx \ --sbin-path=/usr/sbin \ --conf-path=/etc/nginx \ --pid-path=/var/run \ --lock-path=/var/lock/subsys