Update inotify/opt/nginx_change_monitor.sh

This commit is contained in:
2025-01-27 01:08:30 +01:00
parent f6b91c5f13
commit 09cdd82847
-4
View File
@@ -1,12 +1,9 @@
#!/bin/bash #!/bin/bash
# Directory to monitor
TARGET_DIR="/etc/nginx/live/" TARGET_DIR="/etc/nginx/live/"
# Log file for tracking changes
LOG_FILE="/var/log/nginx_change_monitor.log" LOG_FILE="/var/log/nginx_change_monitor.log"
# Function to check Nginx configuration and reload if valid
reload_nginx_if_valid() { reload_nginx_if_valid() {
echo "Checking Nginx configuration..." | tee -a "$LOG_FILE" echo "Checking Nginx configuration..." | tee -a "$LOG_FILE"
if nginx -t &>> "$LOG_FILE"; then if nginx -t &>> "$LOG_FILE"; then
@@ -17,7 +14,6 @@ reload_nginx_if_valid() {
fi fi
} }
# Monitor the directory for changes using inotifywait
echo "Starting Nginx change monitor for directory: $TARGET_DIR" | tee -a "$LOG_FILE" echo "Starting Nginx change monitor for directory: $TARGET_DIR" | tee -a "$LOG_FILE"
inotifywait -m -r -e modify,create,delete --format '%w%f %e' "$TARGET_DIR" | while read FILE EVENT inotifywait -m -r -e modify,create,delete --format '%w%f %e' "$TARGET_DIR" | while read FILE EVENT
do do