File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed
Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
2- # script to watch changes in WATCH_DIR and reload nginx
2+ # script to watch changes in WATCH_DIR and reload nginx on .conf file changes
33
44export WATCH_DIR=${WATCH_DIR:-/ etc/ nginx}
55
6- echo " [nginx-reloader] Watching directory: ${WATCH_DIR} " >&2
7-
8- EXCLUDES=' .*\\.swp$|.*\\.log$|.*\\.tar\\.gz$'
6+ echo " [nginx-reloader] Watching directory: ${WATCH_DIR} for *.conf files" >&2
97
108while true
119do
12- inotifywait --recursive --exclude " ${EXCLUDES} " -e create -e modify -e delete -e move " ${WATCH_DIR} "
13- nginx -t
14- if [[ $? -eq 0 ]]; then
15- echo " Detected Nginx Configuration Change"
16- echo " Executing: nginx -s reload"
17- nginx -s reload
10+ FILE=$( inotifywait --recursive --format ' %f' -e create -e modify -e delete -e move " ${WATCH_DIR} " 2> /dev/null)
11+
12+ if [[ " ${FILE} " == * .conf ]]; then
13+ echo " [nginx-reloader] Detected change in: ${FILE} "
14+ nginx -t
15+ if [[ $? -eq 0 ]]; then
16+ echo " [nginx-reloader] Config valid, executing: nginx -s reload"
17+ nginx -s reload
18+ else
19+ echo " [nginx-reloader] Config test failed, skipping reload"
20+ fi
1821 fi
1922done
You can’t perform that action at this time.
0 commit comments