Skip to content

Commit a9caac2

Browse files
committed
reloader update
1 parent 50ab4a3 commit a9caac2

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

nginx-f1/nginx-reloader.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
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

44
export 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

108
while true
119
do
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
1922
done

0 commit comments

Comments
 (0)