Skip to content

Commit dfc1231

Browse files
authored
Merge pull request #2035 from casperklein/crond
Make crond and cron job output visible in "docker log"
2 parents 77bee10 + a9870fd commit dfc1231

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ RUN cd /etc/.pihole && \
9898
echo "${PIHOLE_DOCKER_TAG}" > /pihole.docker.tag
9999

100100
COPY --chmod=0755 bash_functions.sh /usr/bin/bash_functions.sh
101+
COPY --chmod=0755 prefix-time.sh /usr/bin/prefix-time.sh
101102
COPY --chmod=0755 start.sh /usr/bin/start.sh
102103

103104
EXPOSE 53 53/udp

src/bash_functions.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ start_cron() {
8989
echo " [!] Failed to install crontab - scheduled tasks (gravity, update checker) will not run"
9090
fi
9191

92-
/usr/sbin/crond
92+
# Run crond in foreground, prefix each line from STDIN/STDOUT with the current date/time/timezone and
93+
# write to PID 1 STDOUT (docker log)
94+
{ /usr/sbin/crond -f -d 6 |& prefix-time.sh; } &
9395
echo ""
9496
}
9597

src/prefix-time.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Prefix each line from STDIN with the current date/time/timezone and write to PID 1 STDOUT (docker log)
4+
while IFS= read -r line; do
5+
printf '%s %s\n' "$(date '+%F %T.%3N %Z')" "$line" >>/proc/1/fd/1
6+
done

0 commit comments

Comments
 (0)