スクリプトで構成の変更が検出されたときに、inotifywait を使用して nginx を再起動したいと考えています。問題は、デーモン モードで実行すると、nginx が再起動し続けることです。
スクリプトは次のようになります。
while inotifywait -d -o /var/log/bootstrap.log --format '%T %:e %w' --timefmt '%Y.%m.%d %H:%M:%S' -e modify,create,delete,move,attrib $(find -L /etc/nginx -type f)
do
NGX_STATUS=$(nginx -t 2>&1)
NGX_CFG_STATUS=$(echo $NGX_STATUS | grep successful)
if [[ $(echo $?) == 0 ]]; then
/etc/init.d/nginx restart
else
echo $NGX_STATUS | tee -a /var/log/bootstrap.log
fi
done
注: このスクリプトは、docker エントリポイント スクリプトの一部です。