From 865a84c0d430ef479349138328ceafd2e05405e6 Mon Sep 17 00:00:00 2001 From: acaranta Date: Sat, 19 Nov 2022 21:17:03 +0100 Subject: [PATCH] upgraded inotifyreloader to allow for simpler items adding like certs and now maps --- inotifreload.sh | 93 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/inotifreload.sh b/inotifreload.sh index 8cb7cf4..33d095b 100755 --- a/inotifreload.sh +++ b/inotifreload.sh @@ -17,39 +17,76 @@ while true; do pgrep haproxy >/run/haproxy.pid fi - #start an inotifywait (timeout -s <#> seconds) - # inotifywait -t 10 -q -e close_write,moved_to,create /hacfg/$HASVC 2>&1 >/dev/null + # Build NOTIFY items list + NOTIFPATHS=("$HASVC") + # Certs if [ -d /hacfg/certs ]; then - inotifywait -t 10 -q -e close_write,moved_to,create -r /hacfg/$HASVC /hacfg/certs 2>&1 >/dev/null - else - inotifywait -t 10 -q -e close_write,moved_to,create /hacfg/$HASVC 2>&1 >/dev/null + NOTIFPATHS+=("certs") fi - #If the config did not really change don't do anything - diff /hacfg/$HASVC /etc/haproxy/$HASVC 2>&1 >/dev/null - if [ $? -gt 0 ]; then - echo "$(date) - Found changes in $HASVC file..." - #if it changed, then copy it and set for reload - cp -f /hacfg/$HASVC /etc/haproxy/$HASVC - RELOAD=1 - fi + #maps + if [ -d /hacfg/maps ]; then + NOTIFPATHS+=("maps") + fi - #If the certificate store did not really change don't do anything - if [ -d /hacfg/certs ]; then - #Check if initial sync is needed - if [ ! -d /etc/haproxy/certs ]; then - rsync -ad /hacfg/certs /etc/haproxy --delete - fi - - #Check for difference - diff /hacfg/certs /etc/haproxy/certs 2>&1 >/dev/null - if [ $? -gt 0 ]; then - echo "$(date) - Found changes in /hacfg/certs directory ..." - #if it changed, then copy it and set for reload - rsync -ad /hacfg/certs /etc/haproxy --delete - RELOAD=1 - fi + # Build Paths list for inotify + HALIST="" + for item in "${NOTIFPATHS[@]}" + do + echo "Found /hacfg/$item " + HALIST=$HALIST" /hacfg/$item" + done + + #start an inotifywait (timeout -s <#> seconds) + # inotifywait -t 10 -q -e close_write,moved_to,create /hacfg/$HASVC 2>&1 >/dev/null + inotifywait -t 10 -q -e close_write,moved_to,create -r $HALIST 2>&1 >/dev/null + + # Check and sync changes + for item in "${NOTIFPATHS[@]}" + do + if [ -d /hacfg/$item ]; then + #Check if initial sync is needed + if [ ! -d /etc/haproxy/$item ]; then + rsync -ad /hacfg/$item /etc/haproxy --delete + fi + + #Check for difference + diff /hacfg/$item /etc/haproxy/$item 2>&1 >/dev/null + if [ $? -gt 0 ]; then + echo "$(date) - Found changes in /hacfg/$item directory ..." + #if it changed, then copy it and set for reload + rsync -ad /hacfg/$item /etc/haproxy --delete + RELOAD=1 + fi fi + done + + + # #If the config did not really change don't do anything + # diff /hacfg/$HASVC /etc/haproxy/$HASVC 2>&1 >/dev/null + # if [ $? -gt 0 ]; then + # echo "$(date) - Found changes in $HASVC file..." + # #if it changed, then copy it and set for reload + # cp -f /hacfg/$HASVC /etc/haproxy/$HASVC + # RELOAD=1 + # fi + + # #If the certificate store did not really change don't do anything + # if [ -d /hacfg/certs ]; then + # #Check if initial sync is needed + # if [ ! -d /etc/haproxy/certs ]; then + # rsync -ad /hacfg/certs /etc/haproxy --delete + # fi + + # #Check for difference + # diff /hacfg/certs /etc/haproxy/certs 2>&1 >/dev/null + # if [ $? -gt 0 ]; then + # echo "$(date) - Found changes in /hacfg/certs directory ..." + # #if it changed, then copy it and set for reload + # rsync -ad /hacfg/certs /etc/haproxy --delete + # RELOAD=1 + # fi + # fi # If Reload is needed, do it if [ $RELOAD -gt 0 ]; then