From 2315d99a46f4d1acd2a130df0e2ef709664c2afb Mon Sep 17 00:00:00 2001 From: acaranta Date: Wed, 21 Apr 2021 23:38:51 +0200 Subject: [PATCH] Added check if certs exists and manages it --- inotifreload.sh | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/inotifreload.sh b/inotifreload.sh index 578cb2b..0be20f7 100755 --- a/inotifreload.sh +++ b/inotifreload.sh @@ -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 @@ -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