Skip to content

Commit

Permalink
Added check if certs exists and manages it
Browse files Browse the repository at this point in the history
  • Loading branch information
acaranta committed Apr 21, 2021
1 parent ccb36bf commit 2315d99
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions inotifreload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ while true; do
fi
#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 -r /hacfg 2>&1 >/dev/null
inotifywait -t 10 -q -e close_write,moved_to,create -r /hacfg 2>&1 >/dev/null

#If the config or certificate store did not really change don't do anything
diff /hacfg/$HASVC /etc/haproxy/$HASVC 2>&1 >/dev/null
Expand All @@ -23,19 +23,24 @@ while true; do
cp -f /hacfg/$HASVC /etc/haproxy/$HASVC
RELOAD=1
fi

if [ -d /hacfg/certs ]; then
if [ ! -d /etc/haproxy/certs ]; then
mkdir /etc/haproxy/certs
cp -rf /hacfg/certs/* /etc/haproxy/certs/
fi
diff /hacfg/certs /etc/haproxy/certs 2>&1 >/dev/null
if [ $? -gt 0 ]; then
echo "$(date) - Found changes in /hacfg/certs file..."
#if it changed, then copy it and reload properly haproxy
cp -rf /hacfg/certs /etc/haproxy/certs
RELOAD=1
fi

diff /hacfg/certs /etc/haproxy/certs 2>&1 >/dev/null
if [ $? -gt 0 ]; then
echo "$(date) - Found changes in /hacfg/certs file..."
#if it changed, then copy it and reload properly haproxy
cp -rf /hacfg/certs /etc/haproxy/certs
RELOAD=1
if [ $RELOAD -gt 0 ]; then
echo "$(date) - Found changes... gracefully reloading HAProxy"
#if it changed, then copy it and reload properly haproxy
haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/$HASVC -D -p /run/haproxy.pid -sf $(cat /run/haproxy.pid)
fi
fi

if [ $RELOAD -gt 0 ]; then
echo "$(date) - Found changes... gracefully reloading HAProxy"
#if it changed, then copy it and reload properly haproxy
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 2315d99

Please sign in to comment.