Added new parameter CRON_MINUTE to docker image

This can be used to start the cron on a specific minute within
the hour. By default, the cron will run in the 10th minute
This commit is contained in:
2025-12-06 14:59:43 -08:00
parent 8d4d317330
commit 10be012150
2 changed files with 15 additions and 14 deletions

View File

@@ -2,6 +2,9 @@
set -e
CRON_MINUTE=${CRON_MINUTE:-10}
PORT=${PORT:-8080}
# Ensure data directory exists
mkdir -p /var/www/data/speed
@@ -17,20 +20,17 @@ chmod -R a+rwX /var/www/data || true
# We run it in background so server starts promptly. The cron will run hourly.
/usr/local/bin/run_speed_test.sh || true &
# Ensure the cron job exists in root's crontab (so `crontab -l` shows it)
CRON_ENTRY="* * * * * /usr/local/bin/run_speed_test.sh >> /var/log/cron.log 2>&1"
if crontab -l 2>/dev/null | grep -F "$CRON_ENTRY" >/dev/null 2>&1; then
echo "cron entry already present"
# Ensure the cron job exists in Cron
CRON_FILE=/etc/cron.d/speedtest-cron
if grep run_speed_test ${CRON_FILE}; then
echo "cron entry already present"
else
(crontab -l 2>/dev/null; echo "$CRON_ENTRY") | crontab -
echo "installed cron entry into root crontab"
echo ${CRON_MINUTE} '* * * * /usr/local/bin/run_speed_test.sh >> /var/log/cron.log 2>&1' > ${CRON_FILE}
fi
# Start Debian cron in background
service cron start || cron || true
PORT=${PORT:-8080}
# Start busybox httpd serving /var/www on configured port in foreground
if command -v busybox >/dev/null 2>&1; then
echo "starting busybox httpd on port ${PORT} serving /var/www"