Skip to content

Commit

Permalink
Corrected check loops and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
acaranta committed Apr 22, 2021
1 parent b05e725 commit 543ba58
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions inotifreload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 543ba58

Please sign in to comment.