こんにちは。hacknoteのr.katoです。
今回はSSL証明書の更新のときなどに使用する、configtestとGraceful Restartの紹介です。
configtest
confファイルの構文チェックをしてくれます。
$ httpd -t #apacheの場合 $ nginx -t #nginxの場合
Graceful Restart
通常のrestartを行うと瞬断が発生したり、ユーザーの処理中の手続きが正常終了せずやり直しになってしまったりするのを防ぐための特殊なrestartをGraceful Restartといいます。
apacheの場合
$ apachectl graceful $ httpd -k graceful
上記のどちらでも良いようです。
また、 /usr/lib/systemd/system/httpd.service を見る限りでは
$ cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful とあるので systemctl reload httpd でも良さそうです。
nginxの場合
公式ドキュメントによると次のようにすれば良いとのことです。
$ kill -s HUP NINGXPID
(NINGXPIDは ps aux |grep nginx で出力されたroot userの物を使えばよいそうです。)
/usr/lib/systemd/system/nginx.service を見る限りでは
$ cat /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target
ExecReload=/bin/kill -s HUP $MAINPID とあるので systemctl reload nginx でも問題なさそうです。


