Adjust for compatibility with standard-base

This commit is contained in:
Eric Nemchik
2022-09-22 13:34:53 +00:00
parent 19886fd086
commit 7a234a8830
2 changed files with 35 additions and 40 deletions
@@ -1,45 +1,41 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
DEFAULT_WATCH=( \
/config/nginx/authelia-location.conf \
/config/nginx/authelia-server.conf \
/config/nginx/geoip2.conf \
/config/nginx/ldap.conf \
/config/nginx/nginx.conf \
/config/nginx/proxy-confs \
/config/nginx/proxy.conf \
/config/nginx/site-confs \
/config/nginx/ssl.conf \
)
DEFAULT_WATCH=()
mapfile -t DEFAULT_WATCH < <(find /config/nginx -type f -name '*.conf' -print)
DEFAULT_WATCH+=("/config/nginx/proxy-confs" "/config/nginx/site-confs")
# start with an empty array for active watch
ACTIVE_WATCH=()
echo "MOD Auto-reload: Watching the following files/folders for changes"
for i in ${DEFAULT_WATCH[@]}; do
for i in "${DEFAULT_WATCH[@]}"; do
if [ -f "${i}" ] || [ -d "${i}" ]; then
echo "${i}"
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
ACTIVE_WATCH+=("${i}")
fi
done
for i in $(echo "$WATCHLIST" | tr "|" " "); do
for i in $(echo "${WATCHLIST}" | tr "|" " "); do
if [ -f "${i}" ] || [ -d "${i}" ]; then
echo "${i}"
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
ACTIVE_WATCH+=("${i}")
fi
done
function wait_for_changes {
inotifywait -rq \
--event modify,move,create,delete \
${ACTIVE_WATCH}
"${ACTIVE_WATCH[@]}"
}
while wait_for_changes; do
if ! cat /etc/nginx/nginx.conf | grep "/config/nginx/nginx.conf"; then
export NGINX_CONF="-c /config/nginx/nginx.conf"
NGINX_CONF=()
if ! grep -q "/config/nginx/nginx.conf" /etc/nginx/nginx.conf; then
NGINX_CONF=("-c" "/config/nginx/nginx.conf")
fi
if /usr/sbin/nginx ${NGINX_CONF} -t; then
if /usr/sbin/nginx "${NGINX_CONF[@]}" -t; then
echo "Changes to nginx config detected and the changes are valid, reloading nginx"
/usr/sbin/nginx ${NGINX_CONF} -s reload
/usr/sbin/nginx "${NGINX_CONF[@]}" -s reload
else
echo "Changes to nginx config detected but the changes are not valid, skipping nginx reload. Please fix your config."
fi
fi
done
+18 -19
View File
@@ -1,42 +1,41 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
DEFAULT_WATCH=( \
/config/nginx/authelia-location.conf \
/config/nginx/authelia-server.conf \
/config/nginx/geoip2.conf \
/config/nginx/ldap.conf \
/config/nginx/nginx.conf \
/config/nginx/proxy-confs \
/config/nginx/proxy.conf \
/config/nginx/site-confs \
/config/nginx/ssl.conf \
)
DEFAULT_WATCH=()
mapfile -t DEFAULT_WATCH < <(find /config/nginx -type f -name '*.conf' -print)
DEFAULT_WATCH+=("/config/nginx/proxy-confs" "/config/nginx/site-confs")
# start with an empty array for active watch
ACTIVE_WATCH=()
echo "MOD Auto-reload: Watching the following files/folders for changes"
for i in ${DEFAULT_WATCH[@]}; do
for i in "${DEFAULT_WATCH[@]}"; do
if [ -f "${i}" ] || [ -d "${i}" ]; then
echo "${i}"
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
ACTIVE_WATCH+=("${i}")
fi
done
for i in $(echo "$WATCHLIST" | tr "|" " "); do
for i in $(echo "${WATCHLIST}" | tr "|" " "); do
if [ -f "${i}" ] || [ -d "${i}" ]; then
echo "${i}"
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
ACTIVE_WATCH+=("${i}")
fi
done
function wait_for_changes {
inotifywait -rq \
--event modify,move,create,delete \
${ACTIVE_WATCH}
"${ACTIVE_WATCH[@]}"
}
while wait_for_changes; do
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
NGINX_CONF=()
if ! grep -q "/config/nginx/nginx.conf" /etc/nginx/nginx.conf; then
NGINX_CONF=("-c" "/config/nginx/nginx.conf")
fi
if /usr/sbin/nginx "${NGINX_CONF[@]}" -t; then
echo "Changes to nginx config detected and the changes are valid, reloading nginx"
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
/usr/sbin/nginx "${NGINX_CONF[@]}" -s reload
else
echo "Changes to nginx config detected but the changes are not valid, skipping nginx reload. Please fix your config."
fi
fi
done