Skip to content

Commit

Permalink
upgraded inotifyreloader to allow for simpler items adding like certs…
Browse files Browse the repository at this point in the history
… and now maps
  • Loading branch information
acaranta committed Nov 19, 2022
1 parent eff60ba commit 865a84c
Showing 1 changed file with 65 additions and 28 deletions.
93 changes: 65 additions & 28 deletions inotifreload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 865a84c

Please sign in to comment.