Skip to content

Commit

Permalink
Check all host changes for config validity but only reload nginx once
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Jun 12, 2024
1 parent e047e3d commit c582226
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
30 changes: 23 additions & 7 deletions root/app/auto-proxy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/with-contenv bash

AUTO_GEN=""
REMOVED_CONTAINERS=""
# figure out which containers to generate confs for or which confs to remove
if [ ! -f /auto-proxy/enabled_containers_"$DOCKER_HOST_NAME" ]; then
docker ps --filter "label=swag=enable" --format "{{.Names}}" > /auto-proxy/enabled_containers_"$DOCKER_HOST_NAME"
Expand Down Expand Up @@ -187,11 +188,26 @@ DUDE
fi
done

if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
echo "**** Changes to nginx config are valid, reloading nginx ****"
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
else
echo "**** Changes to nginx config are not valid, skipping nginx reload. Please double check the config including the auto-proxy confs. ****"
fi
if [ "${DIAG_EXIT}" == "true" ]; then
if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are valid ****"
return 200;
else
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are not valid. Please double check the config including the auto-proxy confs. ****"
return 201;
fi
else
return 0;
fi
else
if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are valid, reloading nginx ****"
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
else
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are not valid, skipping nginx reload. Please double check the config including the auto-proxy confs. ****"
fi
fi
fi

22 changes: 22 additions & 0 deletions root/app/docker-wrap.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/with-contenv bash

RELOAD_NGINX="false"
NGINX_VALID="true"
DIAG_EXIT="true"

HOST_TLD_ORIG=${AUTO_PROXY_HOST_TLD:=*}
if [[ -v FIRST_RUN ]];then
echo '**** Auto Proxy - first-run ****'
Expand Down Expand Up @@ -33,6 +37,12 @@ if [[ -v DOCKER_HOST ]];then
echo "**** Auto Proxy - Generating proxies for => Host: ${DOCKER_HOST} | Name: ${DOCKER_HOST_NAME:-N/A} | Default Upstream IP: ${UPSTREAM_HOST} | Host TLD: ${AUTO_PROXY_HOST_TLD} ****"
fi
. /app/auto-proxy.sh
RES=$?
if [ $RES == 201 ]; then
NGINX_VALID="false"
elif [ $RES == 200 ]; then
RELOAD_NGINX="true"
fi

let INDEX=${INDEX}+1
done
Expand All @@ -46,7 +56,19 @@ if [ -S /var/run/docker.sock ]; then
unset DOCKER_HOST
unset UPSTREAM_HOST
. /app/auto-proxy.sh
RES=$?
if [ $RES == 201 ]; then
NGINX_VALID="false"
elif [ $RES == 200 ]; then
RELOAD_NGINX="true"
fi
fi

if [ "${NGINX_VALID}" == "true" ] && [ "${RELOAD_NGINX}" == "true" ]; then
echo "**** All changes to nginx config are valid, reloading nginx ****"
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
fi

if [[ -v FIRST_RUN ]];then
echo '**** Auto Proxy - first-run finished ****'
fi

0 comments on commit c582226

Please sign in to comment.