Skip to content

Commit e249a71

Browse files
committed
Allow to stream webserver.log to docker output
Signed-off-by: yubiuser <github@yubiuser.dev>
1 parent 76b3b66 commit e249a71

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/start.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ start() {
5555
fix_capabilities
5656
sh /opt/pihole/pihole-FTL-prestart.sh
5757

58-
# Get the FTL log file path from the config
58+
# Get the FTL and web log file path from the config
5959
FTLlogFile=$(getFTLConfigValue files.log.ftl)
60+
WEBlogFile=$(getFTLConfigValue files.log.webserver)
6061

61-
# Get the EOF position of the FTL log file so that we can tail from there later.
62-
local startFrom
63-
startFrom=$(stat -c%s "${FTLlogFile}")
62+
# Get the EOF position of the FTL and webserver log file so that we can tail from there later.
63+
local FTLstartFrom WEBstartFrom
64+
FTLstartFrom=$(stat -c%s "${FTLlogFile}")
65+
WEBstartFrom=$(stat -c%s "${WEBlogFile}")
6466

6567
echo " [i] Starting pihole-FTL ($FTL_CMD) as ${DNSMASQ_USER}"
6668
echo ""
@@ -75,7 +77,7 @@ start() {
7577
CAPSH_PID=$!
7678

7779
# Wait for FTL to start by monitoring the FTL log file for the "FTL started" line
78-
if ! timeout 30 tail -F -c +$((startFrom + 1)) -- "${FTLlogFile}" | grep -q '########## FTL started'; then
80+
if ! timeout 30 tail -F -c +$((FTLstartFrom + 1)) -- "${FTLlogFile}" | grep -q '########## FTL started'; then
7981
echo " [!] ERROR: Did not find 'FTL started' message in ${FTLlogFile} in 30 seconds, stopping container"
8082
exit 1
8183
fi
@@ -89,10 +91,19 @@ start() {
8991

9092
if [ "${TAIL_FTL_LOG:-1}" -eq 1 ]; then
9193
# Start tailing the FTL log file from the EOF position we recorded on container start
92-
tail -F -c +$((startFrom + 1)) -- "${FTLlogFile}" &
94+
tail -F -c +$((FTLstartFrom + 1)) -- "${FTLlogFile}" &
9395
else
9496
echo " [i] FTL log output is disabled. Remove the Environment variable TAIL_FTL_LOG, or set it to 1 to enable FTL log output."
9597
fi
98+
if [ "${TAIL_WEB_LOG:-1}" -eq 1 ]; then
99+
# Start tailing the web log file from the EOF position we recorded on container start
100+
tail -F -c +$((WEBstartFrom + 1)) -- "${WEBlogFile}" &
101+
else
102+
echo " [i] Web server log output is disabled. Remove the Environment variable TAIL_WEB_LOG, or set it to 1 to enable web server log output."
103+
fi
104+
105+
106+
96107

97108
# Wait for the capsh process (which spawned FTL) to finish
98109
wait $CAPSH_PID

test/test_default.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ teardown_file() {
3939
assert_success
4040
}
4141

42+
# ---- Web log is tailed to docker log ------------------------------------------------
43+
44+
@test "Web server log is tailed to docker log" {
45+
run docker logs "$CONTAINER"
46+
assert_success
47+
assert_output --partial "Initializing HTTP server on ports"
48+
}
49+
4250
# ---- Web password setup -----------------------------------------------------
4351

4452
@test "Random password is assigned on fresh start" {

test/test_env_vars.bats

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ setup_file() {
1212
-e FTLCONF_webserver_port=8080 \
1313
-e FTLCONF_dns_upstreams="8.8.8.8;1.1.1.1" \
1414
-e ADDITIONAL_PACKAGES=wget \
15-
-e TAIL_FTL_LOG=0)
15+
-e TAIL_FTL_LOG=0 \
16+
-e TAIL_WEB_LOG=0)
1617
wait_for_log "$CONTAINER" "FTL log output is disabled"
1718
export CONTAINER
1819
}
@@ -76,3 +77,14 @@ teardown_file() {
7677
assert_output --partial "FTL log output is disabled"
7778
refute_output --partial "########## FTL started"
7879
}
80+
81+
# ---- TAIL_WEB_LOG disabled --------------------------------------------------
82+
83+
@test "TAIL_WEB_LOG=0 suppresses web server log output in docker logs" {
84+
# TAIL_WEB_LOG defaults to 1 (enabled); the default container exercises that path.
85+
# This test verifies the opt-out case.
86+
run docker logs "$CONTAINER"
87+
assert_success
88+
assert_output --partial "Web server log output is disabled"
89+
refute_output --partial "Initializing HTTP server on ports"
90+
}

0 commit comments

Comments
 (0)