Skip to content

Commit c582226

Browse files
committed
Check all host changes for config validity but only reload nginx once
1 parent e047e3d commit c582226

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

root/app/auto-proxy.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/with-contenv bash
22

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

190-
if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then
191-
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
192-
echo "**** Changes to nginx config are valid, reloading nginx ****"
193-
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
194-
else
195-
echo "**** Changes to nginx config are not valid, skipping nginx reload. Please double check the config including the auto-proxy confs. ****"
196-
fi
191+
if [ "${DIAG_EXIT}" == "true" ]; then
192+
if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then
193+
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
194+
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are valid ****"
195+
return 200;
196+
else
197+
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are not valid. Please double check the config including the auto-proxy confs. ****"
198+
return 201;
199+
fi
200+
else
201+
return 0;
202+
fi
203+
else
204+
if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then
205+
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
206+
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are valid, reloading nginx ****"
207+
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
208+
else
209+
echo "**** $DOCKER_HOST_NAME - Changes to nginx config are not valid, skipping nginx reload. Please double check the config including the auto-proxy confs. ****"
210+
fi
211+
fi
197212
fi
213+

root/app/docker-wrap.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/with-contenv bash
22

3+
RELOAD_NGINX="false"
4+
NGINX_VALID="true"
5+
DIAG_EXIT="true"
6+
37
HOST_TLD_ORIG=${AUTO_PROXY_HOST_TLD:=*}
48
if [[ -v FIRST_RUN ]];then
59
echo '**** Auto Proxy - first-run ****'
@@ -33,6 +37,12 @@ if [[ -v DOCKER_HOST ]];then
3337
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} ****"
3438
fi
3539
. /app/auto-proxy.sh
40+
RES=$?
41+
if [ $RES == 201 ]; then
42+
NGINX_VALID="false"
43+
elif [ $RES == 200 ]; then
44+
RELOAD_NGINX="true"
45+
fi
3646

3747
let INDEX=${INDEX}+1
3848
done
@@ -46,7 +56,19 @@ if [ -S /var/run/docker.sock ]; then
4656
unset DOCKER_HOST
4757
unset UPSTREAM_HOST
4858
. /app/auto-proxy.sh
59+
RES=$?
60+
if [ $RES == 201 ]; then
61+
NGINX_VALID="false"
62+
elif [ $RES == 200 ]; then
63+
RELOAD_NGINX="true"
64+
fi
4965
fi
66+
67+
if [ "${NGINX_VALID}" == "true" ] && [ "${RELOAD_NGINX}" == "true" ]; then
68+
echo "**** All changes to nginx config are valid, reloading nginx ****"
69+
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
70+
fi
71+
5072
if [[ -v FIRST_RUN ]];then
5173
echo '**** Auto Proxy - first-run finished ****'
5274
fi

0 commit comments

Comments
 (0)