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:
13
Dockerfile
13
Dockerfile
@@ -2,6 +2,13 @@ FROM debian:stable-slim
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Default is to run cron job in the 10th minute of each hour
|
||||
# You can override at runtime with -e CRON_MINUTE=xx
|
||||
ENV CRON_MINUTE=10
|
||||
# Default port for http server inside container.
|
||||
# You can override at runtime with -e PORT=xxxx
|
||||
ENV PORT=8080
|
||||
|
||||
# Install required packages: curl, cron, busybox (httpd), ca-certificates
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends curl cron busybox ca-certificates gnupg dirmngr \
|
||||
@@ -25,14 +32,8 @@ COPY start.sh /usr/local/bin/start.sh
|
||||
# Ensure scripts are executable
|
||||
RUN chmod +x /usr/local/bin/run_speed_test.sh /usr/local/bin/start.sh
|
||||
|
||||
# Add cron job to run every hour at minute 0
|
||||
RUN printf "0 * * * * root /usr/local/bin/run_speed_test.sh >> /var/log/cron.log 2>&1\n" > /etc/cron.d/speedtest-cron \
|
||||
&& chmod 0644 /etc/cron.d/speedtest-cron
|
||||
|
||||
# Expose default HTTP port and declare data volume
|
||||
VOLUME ["/var/www/data/speed"]
|
||||
# Default port for http server inside container. You can override at runtime with -e PORT=xxxx
|
||||
ENV PORT=8080
|
||||
EXPOSE 8080
|
||||
|
||||
# Start script will launch cron and the HTTP server
|
||||
|
||||
14
start.sh
14
start.sh
@@ -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
|
||||
# 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"
|
||||
|
||||
Reference in New Issue
Block a user