Skip to content

Commit 5ba3577

Browse files
authored
Merge pull request #503 from linuxserver/swag-auto-reload-standard-base
Adjust for compatibility with standard-base
2 parents 19886fd + d83f92e commit 5ba3577

File tree

3 files changed

+30
-62
lines changed
  • root/etc
    • s6-overlay/s6-rc.d/svc-mod-swag-auto-reload
    • services.d/inotify

3 files changed

+30
-62
lines changed

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
# Auto-reload - Docker mod for Nginx based images
22

3-
This mod allows Nginx to be reloaded automatically whenever there are valid changes to the following files and folders:
4-
- /config/nginx/authelia-location.conf
5-
- /config/nginx/authelia-server.conf
6-
- /config/nginx/geoip2.conf
7-
- /config/nginx/ldap.conf
8-
- /config/nginx/nginx.conf
9-
- /config/nginx/proxy-confs
10-
- /config/nginx/proxy.conf
11-
- /config/nginx/site-confs
12-
- /config/nginx/ssl.conf
3+
This mod allows Nginx to be reloaded automatically whenever there are new files, or valid changes to the files in `/config/nginx`.
134

145
In the container's docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:swag-auto-reload`
156

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,32 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

3-
DEFAULT_WATCH=( \
4-
/config/nginx/authelia-location.conf \
5-
/config/nginx/authelia-server.conf \
6-
/config/nginx/geoip2.conf \
7-
/config/nginx/ldap.conf \
8-
/config/nginx/nginx.conf \
9-
/config/nginx/proxy-confs \
10-
/config/nginx/proxy.conf \
11-
/config/nginx/site-confs \
12-
/config/nginx/ssl.conf \
13-
)
14-
15-
echo "MOD Auto-reload: Watching the following files/folders for changes"
16-
for i in ${DEFAULT_WATCH[@]}; do
17-
if [ -f "${i}" ] || [ -d "${i}" ]; then
18-
echo "${i}"
19-
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
20-
fi
21-
done
22-
for i in $(echo "$WATCHLIST" | tr "|" " "); do
4+
echo "MOD Auto-reload: Watching the following files/folders for changes (excluding .sample and .md files):"
5+
echo "/config/nginx"
6+
ACTIVE_WATCH=("/config/nginx")
7+
for i in $(echo "${WATCHLIST}" | tr "|" " "); do
238
if [ -f "${i}" ] || [ -d "${i}" ]; then
249
echo "${i}"
25-
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
10+
ACTIVE_WATCH+=("${i}")
2611
fi
2712
done
2813

2914
function wait_for_changes {
3015
inotifywait -rq \
3116
--event modify,move,create,delete \
32-
${ACTIVE_WATCH}
17+
--excludei '\.(sample|md)' \
18+
"${ACTIVE_WATCH[@]}"
3319
}
3420

3521
while wait_for_changes; do
36-
if ! cat /etc/nginx/nginx.conf | grep "/config/nginx/nginx.conf"; then
37-
export NGINX_CONF="-c /config/nginx/nginx.conf"
22+
NGINX_CONF=()
23+
if ! grep -q "/config/nginx/nginx.conf" /etc/nginx/nginx.conf; then
24+
NGINX_CONF=("-c" "/config/nginx/nginx.conf")
3825
fi
39-
if /usr/sbin/nginx ${NGINX_CONF} -t; then
26+
if /usr/sbin/nginx "${NGINX_CONF[@]}" -t; then
4027
echo "Changes to nginx config detected and the changes are valid, reloading nginx"
41-
/usr/sbin/nginx ${NGINX_CONF} -s reload
28+
/usr/sbin/nginx "${NGINX_CONF[@]}" -s reload
4229
else
4330
echo "Changes to nginx config detected but the changes are not valid, skipping nginx reload. Please fix your config."
44-
fi
31+
fi
4532
done

root/etc/services.d/inotify/run

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

3-
DEFAULT_WATCH=( \
4-
/config/nginx/authelia-location.conf \
5-
/config/nginx/authelia-server.conf \
6-
/config/nginx/geoip2.conf \
7-
/config/nginx/ldap.conf \
8-
/config/nginx/nginx.conf \
9-
/config/nginx/proxy-confs \
10-
/config/nginx/proxy.conf \
11-
/config/nginx/site-confs \
12-
/config/nginx/ssl.conf \
13-
)
14-
15-
echo "MOD Auto-reload: Watching the following files/folders for changes"
16-
for i in ${DEFAULT_WATCH[@]}; do
4+
echo "MOD Auto-reload: Watching the following files/folders for changes (excluding .sample and .md files):"
5+
echo "/config/nginx"
6+
ACTIVE_WATCH=("/config/nginx")
7+
for i in $(echo "${WATCHLIST}" | tr "|" " "); do
178
if [ -f "${i}" ] || [ -d "${i}" ]; then
189
echo "${i}"
19-
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
20-
fi
21-
done
22-
for i in $(echo "$WATCHLIST" | tr "|" " "); do
23-
if [ -f "${i}" ] || [ -d "${i}" ]; then
24-
echo "${i}"
25-
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
10+
ACTIVE_WATCH+=("${i}")
2611
fi
2712
done
2813

2914
function wait_for_changes {
3015
inotifywait -rq \
3116
--event modify,move,create,delete \
32-
${ACTIVE_WATCH}
17+
--excludei '\.(sample|md)' \
18+
"${ACTIVE_WATCH[@]}"
3319
}
3420

3521
while wait_for_changes; do
36-
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
22+
NGINX_CONF=()
23+
if ! grep -q "/config/nginx/nginx.conf" /etc/nginx/nginx.conf; then
24+
NGINX_CONF=("-c" "/config/nginx/nginx.conf")
25+
fi
26+
if /usr/sbin/nginx "${NGINX_CONF[@]}" -t; then
3727
echo "Changes to nginx config detected and the changes are valid, reloading nginx"
38-
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
28+
/usr/sbin/nginx "${NGINX_CONF[@]}" -s reload
3929
else
4030
echo "Changes to nginx config detected but the changes are not valid, skipping nginx reload. Please fix your config."
41-
fi
31+
fi
4232
done

0 commit comments

Comments
 (0)