From b9543536eef484e9844e0271823e4db951b0dca7 Mon Sep 17 00:00:00 2001 From: acaranta Date: Mon, 19 Apr 2021 19:09:54 +0200 Subject: [PATCH] Added inotify proper reload for certificates --- inotifreload.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/inotifreload.sh b/inotifreload.sh index 07c7a3b..3706fea 100755 --- a/inotifreload.sh +++ b/inotifreload.sh @@ -12,14 +12,30 @@ 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 -e close_write,moved_to,create -r /hacfg 2>&1 >/dev/null + inotifywait -t 10 -q -r /hacfg 2>&1 >/dev/null - #If the file did not really change don't do anything + #If the config or certificate store 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... gracefully reloading HAProxy" + echo "$(date) - Found changes in $HASVC file..." + #if it changed, then copy it and reload properly haproxy + cp -f /hacfg/$HASVC /etc/haproxy/$HASVC + 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 + fi + + if [ $RELOAD -gt 0 ]; then + echo "$(date) - Found changes... gracefully reloading HAProxy" #if it changed, then copy it and reload properly haproxy - cp -f /hacfg/$HASVC /etc/haproxy/$HASVC haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/$HASVC -D -p /run/haproxy.pid -sf $(cat /run/haproxy.pid) fi + RELOAD=0 + done