Skip to content

Commit 5fc14a8

Browse files
committed
configurable reloader time
1 parent a336c9d commit 5fc14a8

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

nginx-f1/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ The `nginx-reloader` daemon watches for configuration file changes and automatic
364364
|----------|---------|-------------|
365365
| `WATCH_DIR` | `/etc/nginx` | Directory to watch for config changes |
366366
| `RELOADER_LOG` | `/var/log/nginx/reloader.log` | Log file path |
367+
| `RELOADER_DELAY` | `2` | Delay in seconds before reload (batches rapid changes) |
367368

368369
### Example Usage
369370

@@ -391,10 +392,9 @@ docker exec nginx-f1 tail -f /var/log/supervisor/nginx-reloader.log
391392
### Example Log Output
392393

393394
```
394-
[2024-01-15 10:30:00] Starting nginx-reloader, watching: /etc/nginx for *.conf files
395-
[2024-01-15 10:35:22] Detected change in: default.conf
396-
[2024-01-15 10:35:22] Config valid, executing: nginx -s reload
397-
[2024-01-15 10:40:15] Ignored non-conf file: nginx.pid
395+
[2024-01-15 10:30:00] Starting nginx-reloader, watching: /etc/nginx for *.conf files (delay: 2s)
396+
[2024-01-15 10:35:22] Detected: default.conf
397+
[2024-01-15 10:35:22] Config valid, reloading nginx
398398
```
399399

400400
## 📊 Monitoring & Logs

nginx-f1/nginx-reloader.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33

44
export WATCH_DIR=${WATCH_DIR:-/etc/nginx}
55
export RELOADER_LOG=${RELOADER_LOG:-/var/log/nginx/reloader.log}
6+
export RELOADER_DELAY=${RELOADER_DELAY:-2}
67

78
log() {
89
local msg="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
910
echo "$msg"
1011
echo "$msg" >> "${RELOADER_LOG}"
1112
}
1213

13-
log "Starting nginx-reloader, watching: ${WATCH_DIR} for *.conf files"
14+
log "Starting nginx-reloader, watching: ${WATCH_DIR} for *.conf files (delay: ${RELOADER_DELAY}s)"
1415

1516
while true
1617
do
1718
FILE=$(inotifywait --recursive --format '%f' -e create -e modify -e delete -e move "${WATCH_DIR}" 2>/dev/null)
1819

1920
if [[ "${FILE}" == *.conf ]]; then
20-
log "Detected change in: ${FILE}"
21+
sleep "${RELOADER_DELAY}"
22+
log "Detected: ${FILE}"
2123
nginx -t
2224
if [[ $? -eq 0 ]]; then
23-
log "Config valid, executing: nginx -s reload"
25+
log "Config valid, reloading nginx"
2426
nginx -s reload
2527
else
2628
log "Config test failed, skipping reload"
2729
fi
28-
else
29-
log "Ignored non-conf file: ${FILE}"
3030
fi
3131
done

0 commit comments

Comments
 (0)