Skip to content

Commit e94bc17

Browse files
committed
[Feat] Allow override of GUI's listen address from Syncthing
configuration file or environs - Replace hardcoded default listen address `0.0.0.0:8384` with 1. Environ lookup from `STGUIHOST` and `STGUIPORT` 2. Static configuration lookup from Syncthing config.xml 3. Default to `0.0.0.0` and `8384`
1 parent 2e8d0a3 commit e94bc17

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ LABEL maintainer="thelamer"
4444

4545
# environment settings
4646
ENV HOME="/config"
47+
ENV STGUIHOST=""
48+
ENV STGUIPORT=""
4749

4850
RUN \
4951
echo "**** create var lib folder ****" && \
@@ -56,5 +58,5 @@ COPY --from=buildstage /tmp/sync/syncthing /usr/bin/
5658
COPY root/ /
5759

5860
# ports and volumes
59-
EXPOSE 8384 22000/tcp 22000/udp 21027/UDP
61+
EXPOSE 8384 22000/tcp 22000/udp 21027/udp
6062
VOLUME /config

Dockerfile.aarch64

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ LABEL maintainer="thelamer"
4444

4545
# environment settings
4646
ENV HOME="/config"
47+
ENV STGUIHOST=""
48+
ENV STGUIPORT=""
4749

4850
RUN \
4951
echo "**** create var lib folder ****" && \
@@ -56,5 +58,5 @@ COPY --from=buildstage /tmp/sync/syncthing /usr/bin/
5658
COPY root/ /
5759

5860
# ports and volumes
59-
EXPOSE 8384 22000/tcp 22000/udp 21027/UDP
61+
EXPOSE 8384 22000/tcp 22000/udp 21027/udp
6062
VOLUME /config

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ services:
7878
- PUID=1000
7979
- PGID=1000
8080
- TZ=Etc/UTC
81+
- STGUIHOST=0.0.0.0 # optional
82+
- STGUIPORT=8384 # optional
8183
volumes:
8284
- /path/to/syncthing/config:/config
8385
- /path/to/data1:/data1
@@ -99,6 +101,8 @@ docker run -d \
99101
-e PUID=1000 \
100102
-e PGID=1000 \
101103
-e TZ=Etc/UTC \
104+
-e STGUIHOST=0.0.0.0 `#optional` \
105+
-e STGUIPORT=8384 `#optional` \
102106
-p 8384:8384 \
103107
-p 22000:22000/tcp \
104108
-p 22000:22000/udp \
@@ -121,9 +125,11 @@ Containers are configured using parameters passed at runtime (such as those abov
121125
| `-p 22000:22000/tcp` | Listening port (TCP) |
122126
| `-p 22000:22000/udp` | Listening port (UDP) |
123127
| `-p 21027:21027/udp` | Protocol discovery |
124-
| `-e PUID=1000` | for UserID - see below for explanation |
125-
| `-e PGID=1000` | for GroupID - see below for explanation |
126-
| `-e TZ=Etc/UTC` | specify a timezone to use, see this [list](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List). |
128+
| `-e PUID=1000` | For UserID - see below for explanation |
129+
| `-e PGID=1000` | For GroupID - see below for explanation |
130+
| `-e TZ=Etc/UTC` | Specify a timezone to use, see this [list](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List). |
131+
| `-e STGUIHOST=0.0.0.0` | Specify the application WebUI service listening address (default to `0.0.0.0` if not overrided by env nor config.xml). |
132+
| `-e STGUIPORT=8384` | Specify the application WebUI service listening port (default to `8384` if not overrided by env nor config.xml). |
127133
| `-v /config` | Configuration files. |
128134
| `-v /data1` | Data1 |
129135
| `-v /data2` | Data2 |
@@ -289,7 +295,7 @@ docker run --rm --privileged lscr.io/linuxserver/qemu-static --reset
289295
Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64`.
290296

291297
## Versions
292-
298+
* **06.12.25:** - [Feat] Allow override of GUI's listen address from Syncthing configuration file or environs
293299
* **16.08.25:** - Rebase to Alpine 3.22.
294300
* **13.08.25:** - Use double-dash long options for syncthing v2.0.0.
295301
* **03.12.24:** - Rebase to Alpine 3.21.

readme-vars.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ available_architectures:
1313
- {arch: "{{ arch_arm64 }}", tag: "arm64v8-latest"}
1414
# container parameters
1515
common_param_env_vars_enabled: true #PGID, PUID, etc, you can set it to 'optional'
16+
params_environs:
17+
- { environ: "STGUIHOST", optional: true, desc: "Override default (0.0.0.0) or config.xml application Web UI service listen address."}
18+
- { environ: "STGUIPort", optional: true, desc: "Override default (8384) or config.xml application Web UI service listen port."}
1619
param_container_name: "{{ project_name }}"
1720
param_usage_include_hostname: 'optional' #you can set it to 'optional'
1821
param_hostname: "{{ project_name }}"
@@ -72,6 +75,7 @@ init_diagram: |
7275
"syncthing:latest" <- Base Images
7376
# changelog
7477
changelogs:
78+
- {date: "06.12.25:", desc: "[Feat] Allow override of GUI's listen address from Syncthing configuration file or environs"}
7579
- {date: "16.08.25:", desc: "Rebase to Alpine 3.22."}
7680
- {date: "13.08.25:", desc: "Use double-dash long options for syncthing v2.0.0."}
7781
- {date: "03.12.24:", desc: "Rebase to Alpine 3.21."}
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4+
# Listen address from:
5+
# 1. Environ
6+
# 2. config
7+
# 3. default (0.0.0.0:8384)
8+
9+
cfg_address=$(
10+
awk -v lookup=0 '
11+
$1 == "<gui" { lookup=1 }
12+
$1 == "</gui>" { lookup=0 }
13+
lookup == 1 { print }
14+
' /config/config.xml 2>/dev/null \
15+
| grep address \
16+
| sed 's|</\?address>||g; s|[[:space:]]||g'
17+
)
18+
19+
cfg_host="${cfg_address%%:*}"
20+
cfg_port="${cfg_address##*:}"
21+
22+
gui_host="${STGUIHOST:-$cfg_host}"
23+
gui_port="${STGUIPORT:-$cfg_port}"
24+
25+
gui_host="${gui_host:-0.0.0.0}"
26+
gui_port="${gui_port:-8384}"
27+
28+
liveliness_target_host=$gui_host
29+
if [[ "x${gui_host}" == "x0.0.0.0" ]]; then
30+
liveliness_target_addr="127.0.0.1"
31+
fi
32+
433
exec \
5-
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 8384" \
34+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z ${liveliness_target_host} ${gui_port}" \
635
s6-setuidgid abc syncthing \
736
--home=/config --no-browser --no-restart \
8-
--gui-address="0.0.0.0:8384"
37+
--gui-address="${gui_host}:${gui_port}"

0 commit comments

Comments
 (0)