I want to use inotifywait to restart nginx when configuration changes are detected in a script. The problem is that if I run it in daemon mode it keep restarting the nginx.
The script looks like this:
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
Note: This script is part of the docker entrypoint script.