Skip to content

Commit 02ed03a

Browse files
committed
Add auto-reload
1 parent 515fdf4 commit 02ed03a

File tree

8 files changed

+50
-0
lines changed

8 files changed

+50
-0
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

+4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ services:
190190
- EXTRA_DOMAINS= #optional
191191
- STAGING=false #optional
192192
- DISABLE_F2B= #optional
193+
- SWAG_AUTORELOAD= #optional
193194
volumes:
194195
- /path/to/swag/config:/config
195196
ports:
@@ -218,6 +219,7 @@ docker run -d \
218219
-e EXTRA_DOMAINS= `#optional` \
219220
-e STAGING=false `#optional` \
220221
-e DISABLE_F2B= `#optional` \
222+
-e SWAG_AUTORELOAD= `#optional` \
221223
-p 443:443 \
222224
-p 80:80 `#optional` \
223225
-v /path/to/swag/config:/config \
@@ -247,6 +249,7 @@ Containers are configured using parameters passed at runtime (such as those abov
247249
| `-e EXTRA_DOMAINS=` | Additional fully qualified domain names (comma separated, no spaces) ie. `example.net,subdomain.example.net,*.example.org` |
248250
| `-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. |
249251
| `-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. |
252+
| `-e SWAG_AUTORELOAD=` | Set to `true` to enable automatic reloading of nginx configs on change. Your filesystem must support inotify. This functionality was previous offered [via mod](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload). |
250253
| `-v /config` | Persistent config files |
251254
| `--read-only=true` | Run container with a read-only filesystem. Please [read the docs](https://docs.linuxserver.io/misc/read-only/). |
252255
| `--cap-add=NET_ADMIN` | Required for fail2Ban to be able to modify iptables rules. |
@@ -417,6 +420,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
417420

418421
## Versions
419422

423+
* **19.01.25:** - Add [Auto Reload](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload) functionality to SWAG.
420424
* **17.12.24:** - Rebase to Alpine 3.21.
421425
* **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).
422426
* **30.08.24:** - Fix zerossl cert revocation.

readme-vars.yml

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ 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 configs on change. Your filesystem must support inotify. This functionality was previous offered [via mod](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload)."}
4142
opt_param_usage_include_ports: true
4243
opt_param_ports:
4344
- {external_port: "80", internal_port: "80", port_desc: "HTTP port (required for HTTP validation and HTTP -> HTTPS redirect)"}
@@ -200,6 +201,7 @@ init_diagram: |
200201
"swag:latest" <- Base Images
201202
# changelog
202203
changelogs:
204+
- {date: "19.01.25:", desc: "Add [Auto Reload](https://github.com/linuxserver/docker-mods/tree/swag-auto-reload) functionality to SWAG."}
203205
- {date: "17.12.24:", desc: "Rebase to Alpine 3.21."}
204206
- {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)."}
205207
- {date: "30.08.24:", desc: "Fix zerossl cert revocation."}

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 files/folders for changes (excluding .sample, .swp, and .md files):"
10+
echo "/config/nginx"
11+
ACTIVE_WATCH=("/config/nginx")
12+
for i in $(echo "${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+
--excludei '\.(sample|md|swp)' \
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)