From 543ba5873abae4251507fda47a008ccbeb5e95d7 Mon Sep 17 00:00:00 2001 From: acaranta Date: Thu, 22 Apr 2021 14:55:06 +0200 Subject: [PATCH] Corrected check loops and comments --- inotifreload.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/inotifreload.sh b/inotifreload.sh index 612e34e..afc2ebd 100755 --- a/inotifreload.sh +++ b/inotifreload.sh @@ -19,32 +19,38 @@ while true; do inotifywait -t 10 -q -e close_write,moved_to,create /hacfg/$HASVC 2>&1 >/dev/null fi - #If the config or certificate store did not really change don't do anything + #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 reload properly haproxy + #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 - mkdir /etc/haproxy/certs - rsync -ad /hacfg/certs /etc/haproxy --delete + 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 reload properly haproxy - rsync -ad /hacfg/certs /haproxy --delete + #if it changed, then copy it and set for reload + rsync -ad /hacfg/certs /haproxy --delete RELOAD=1 fi + fi - if [ $RELOAD -gt 0 ]; then - echo "$(date) - Found changes... gracefully reloading HAProxy" - #reload properly haproxy - echo "### Reloading PID $(cat /run/haproxy.pid) " - haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/$HASVC -D -p /run/haproxy.pid -sf $(cat /run/haproxy.pid) - fi + # If Reload is needed, do it + if [ $RELOAD -gt 0 ]; then + echo "$(date) - Found changes... gracefully reloading HAProxy" + #reload properly haproxy + echo "### Reloading PID $(cat /run/haproxy.pid)" + haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/$HASVC -D -p /run/haproxy.pid -sf $(cat /run/haproxy.pid) fi + done