Skip to content

Commit bffc4c9

Browse files
authored
Merge pull request #537 from linuxserver/auto-reload
2 parents 5a5d0eb + 14cab18 commit bffc4c9

File tree

9 files changed

+56
-4
lines changed

9 files changed

+56
-4
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ RUN \
2929
apk add --no-cache \
3030
fail2ban \
3131
gnupg \
32+
inotify-tools \
3233
iptables-legacy \
3334
memcached \
3435
nginx-mod-http-brotli \

Dockerfile.aarch64

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ RUN \
2929
apk add --no-cache \
3030
fail2ban \
3131
gnupg \
32+
inotify-tools \
3233
iptables-legacy \
3334
memcached \
3435
nginx-mod-http-brotli \

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ services:
190190
- EXTRA_DOMAINS= #optional
191191
- STAGING=false #optional
192192
- DISABLE_F2B= #optional
193+
- SWAG_AUTORELOAD= #optional
194+
- SWAG_AUTORELOAD_WATCHLIST= #optional
193195
volumes:
194196
- /path/to/swag/config:/config
195197
ports:
@@ -218,6 +220,8 @@ docker run -d \
218220
-e EXTRA_DOMAINS= `#optional` \
219221
-e STAGING=false `#optional` \
220222
-e DISABLE_F2B= `#optional` \
223+
-e SWAG_AUTORELOAD= `#optional` \
224+
-e SWAG_AUTORELOAD_WATCHLIST= `#optional` \
221225
-p 443:443 \
222226
-p 80:80 `#optional` \
223227
-v /path/to/swag/config:/config \
@@ -247,6 +251,8 @@ Containers are configured using parameters passed at runtime (such as those abov
247251
| `-e EXTRA_DOMAINS=` | Additional fully qualified domain names (comma separated, no spaces) ie. `example.net,subdomain.example.net,*.example.org` |
248252
| `-e STAGING=false` | Set to `true` to retrieve certs in staging mode. Rate limits will be much higher, but the resulting cert will not pass the browser's security test. Only to be used for testing purposes. |
249253
| `-e DISABLE_F2B=` | Set to `true` to disable the Fail2ban service in the container, if you're already running it elsewhere or using a different IPS. |
254+
| `-e SWAG_AUTORELOAD=` | Set to `true` to enable automatic reloading of nginx confs on change. Your filesystem must support inotify. This functionality was previous offered [via mod](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload). |
255+
| `-e SWAG_AUTORELOAD_WATCHLIST=` | A `|`-separated list of additional folders for auto reload to watch in addition to `/config/nginx` |
250256
| `-v /config` | Persistent config files |
251257
| `--read-only=true` | Run container with a read-only filesystem. Please [read the docs](https://docs.linuxserver.io/misc/read-only/). |
252258
| `--cap-add=NET_ADMIN` | Required for fail2Ban to be able to modify iptables rules. |
@@ -417,6 +423,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
417423

418424
## Versions
419425

426+
* **19.01.25:** - Add [Auto Reload](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload) functionality to SWAG.
420427
* **17.12.24:** - Rebase to Alpine 3.21.
421428
* **21.10.24:** - Fix naming issue with Dynu plugin. If you are using Dynu, please make sure your credentials are set in /config/dns-conf/dynu.ini and your DNSPLUGIN variable is set to dynu (not dynudns).
422429
* **30.08.24:** - Fix zerossl cert revocation.

readme-vars.yml

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ opt_param_env_vars:
3838
- {env_var: "EXTRA_DOMAINS", env_value: "", desc: "Additional fully qualified domain names (comma separated, no spaces) ie. `example.net,subdomain.example.net,*.example.org`"}
3939
- {env_var: "STAGING", env_value: "false", desc: "Set to `true` to retrieve certs in staging mode. Rate limits will be much higher, but the resulting cert will not pass the browser's security test. Only to be used for testing purposes."}
4040
- {env_var: "DISABLE_F2B", env_value: "", desc: "Set to `true` to disable the Fail2ban service in the container, if you're already running it elsewhere or using a different IPS."}
41+
- {env_var: "SWAG_AUTORELOAD", env_value: "", desc: "Set to `true` to enable automatic reloading of nginx confs on change. Your filesystem must support inotify. This functionality was previously offered [via mod](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload)."}
42+
- {env_var: "SWAG_AUTORELOAD_WATCHLIST", env_value: "", desc: "A `|`-separated list of additional folders for auto reload to watch in addition to `/config/nginx`"}
4143
opt_param_usage_include_ports: true
4244
opt_param_ports:
4345
- {external_port: "80", internal_port: "80", port_desc: "HTTP port (required for HTTP validation and HTTP -> HTTPS redirect)"}
@@ -200,6 +202,7 @@ init_diagram: |
200202
"swag:latest" <- Base Images
201203
# changelog
202204
changelogs:
205+
- {date: "19.01.25:", desc: "Add [Auto Reload](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload) functionality to SWAG."}
203206
- {date: "17.12.24:", desc: "Rebase to Alpine 3.21."}
204207
- {date: "21.10.24:", desc: "Fix naming issue with Dynu plugin. If you are using Dynu, please make sure your credentials are set in /config/dns-conf/dynu.ini and your DNSPLUGIN variable is set to dynu (not dynudns)."}
205208
- {date: "30.08.24:", desc: "Fix zerossl cert revocation."}

root/etc/s6-overlay/s6-rc.d/init-permissions-config/run

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# shellcheck shell=bash
33

44
# permissions
5+
find /config/log ! -path '/config/log/logrotate.status' -exec chmod +r {} \+
6+
57
lsiown -R abc:abc \
68
/config
7-
chmod -R +r /config/log
8-
9-
# Workaround for systems with chmod errors
10-
true

root/etc/s6-overlay/s6-rc.d/svc-swag-auto-reload/dependencies.d/init-services

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
3+
4+
if [[ ${SWAG_AUTORELOAD,,} == "true" ]]; then
5+
if [[ -f "/etc/s6-overlay/s6-rc.d/svc-mod-swag-auto-reload/run" ]]; then
6+
echo "ERROR: Legacy SWAG Auto Reload Mod detected, to use the built-in Auto Reload functionality please remove it from your container config."
7+
sleep infinity
8+
else
9+
echo "Auto-reload: Watching the following folders for changes to .conf files:"
10+
echo "/config/nginx"
11+
ACTIVE_WATCH=("/config/nginx")
12+
for i in $(echo "${SWAG_AUTORELOAD_WATCHLIST}" | tr "|" " "); do
13+
if [ -f "${i}" ] || [ -d "${i}" ]; then
14+
echo "${i}"
15+
ACTIVE_WATCH+=("${i}")
16+
fi
17+
done
18+
19+
function wait_for_changes {
20+
inotifywait -rq \
21+
--event modify,move,create,delete \
22+
--includei '\.conf$' \
23+
"${ACTIVE_WATCH[@]}"
24+
}
25+
26+
while wait_for_changes; do
27+
NGINX_CONF=()
28+
if ! grep -q "/config/nginx/nginx.conf" /etc/nginx/nginx.conf; then
29+
NGINX_CONF=("-c" "/config/nginx/nginx.conf")
30+
fi
31+
if /usr/sbin/nginx "${NGINX_CONF[@]}" -t; then
32+
echo "Changes to nginx config detected and the changes are valid, reloading nginx"
33+
/usr/sbin/nginx "${NGINX_CONF[@]}" -s reload
34+
else
35+
echo "Changes to nginx config detected but the changes are not valid, skipping nginx reload. Please fix your config."
36+
fi
37+
done
38+
fi
39+
else
40+
sleep infinity
41+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
longrun

root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-swag-auto-reload

Whitespace-only changes.

0 commit comments

Comments
 (0)