Skip to content

Commit 237837a

Browse files
authored
Merge pull request #186 from linuxserver/swag-auto-reload-dev
swag-auto-reload: initial release
2 parents d1dc6e5 + 45626d3 commit 237837a

File tree

7 files changed

+61
-69
lines changed

7 files changed

+61
-69
lines changed

.github/workflows/BuildImage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Build Image
33
on: [push, pull_request, workflow_dispatch]
44

55
env:
6-
ENDPOINT: "linuxserver/mods" #don't modify
7-
BASEIMAGE: "replace_baseimage" #replace
8-
MODNAME: "replace_modname" #replace
6+
ENDPOINT: "linuxserver/mods"
7+
BASEIMAGE: "swag"
8+
MODNAME: "auto-reload"
99

1010
jobs:
1111
build:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM scratch
22

3-
LABEL maintainer="username"
3+
LABEL maintainer="aptalca"
44

55
# copy local files
66
COPY root/ /

Dockerfile.complex

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
# Rsync - Docker mod for openssh-server
1+
# Auto-reload - Docker mod for Nginx based images
22

3-
This mod adds rsync to openssh-server, to be installed/updated during container start.
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
413

5-
In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync`
14+
In the container's docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:swag-auto-reload`
615

7-
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2`
16+
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:swag-auto-reload|linuxserver/mods:swag-mod2`
817

9-
# Mod creation instructions
18+
If you'd like for Nginx to be reloaded when other files or folders are modified (not included in our default list above), set a new environment variable, `WATCHLIST`, and set it to a list of container relative paths separated by `|` like the below example:
1019

11-
* Fork the repo, create a new branch based on the branch `template`.
12-
* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done.
13-
* Inspect the `root` folder contents. Edit, add and remove as necessary.
14-
* Edit this readme with pertinent info, delete these instructions.
15-
* Finally edit the `.github/workflows/BuildImage.yml`. Customize the build branch, and the vars for `BASEIMAGE` and `MODNAME`.
16-
* Ask the team to create a new branch named `<baseimagename>-<modname>`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch.
17-
* Submit PR against the branch created by the team.
20+
`WATCHLIST="/config/nginx/custom.conf|/config/nginx/customfolder"`

root/etc/cont-init.d/98-vpn-config

Lines changed: 0 additions & 27 deletions
This file was deleted.

root/etc/services.d/inotify/run

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/with-contenv bash
2+
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
23+
if [ -f "${i}" ] || [ -d "${i}" ]; then
24+
echo "${i}"
25+
ACTIVE_WATCH="${ACTIVE_WATCH} ${i}"
26+
fi
27+
done
28+
29+
function wait_for_changes {
30+
inotifywait -rq \
31+
--event modify,move,create,delete \
32+
${ACTIVE_WATCH}
33+
}
34+
35+
while wait_for_changes; do
36+
if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then
37+
echo "Changes to nginx config detected and the changes are valid, reloading nginx"
38+
/usr/sbin/nginx -c /config/nginx/nginx.conf -s reload
39+
else
40+
echo "Changes to nginx config detected but the changes are not valid, skipping nginx reload. Please fix your config."
41+
fi
42+
done

root/etc/services.d/sshvpn/run

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)