home Glamenv-Septzen(ぐらめぬ・ぜぷつぇん)(archive)

技術/Linux/systemd/graceful shutdown or config reload 参考メモ

作成日: 2017-02-06 15:59:22   /   last updated at: 2017-02-06 16:10:46
カテゴリ: Apache Linux systemd 

systemdにてgraceful shutdown or graceful reload などを行うための参考メモ。

CentOS7でのApacheの例:

→ /usr/lib/systemd/system/httpd.service:

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

[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

ポイント:

  1. graceful reloadコマンドは ExecReload 指定になったため、systemctl reload httpd で呼べるようになっている。
  2. デフォルトでは systemctl stop で一気にSIGTERMが送信されてしまうので、それを避けるため、KillSignal=SIGCONT で無害なシグナルを送信するように修正している。代わりに ExecStop ではSIGWINCHを送るようにしており、これは apachectl -k graceful-stop と同等らしい。

systemd本家manページ:

RedHat のユニットファイルの解説:

その他参考:


original url: https://www.glamenv-septzen.net/view/1376