当在脚本中检测到配置更改时,我想使用 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 入口点脚本的一部分。