Initial commit
This commit is contained in:
42
start.sh
Normal file
42
start.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Ensure data directory exists
|
||||
mkdir -p /var/www/data/speed
|
||||
|
||||
# Ensure raw data file exists
|
||||
touch /var/www/data/speed/raw.speedtest.json
|
||||
|
||||
# If the data directory is a mounted volume it may be owned by root; allow writes
|
||||
# by ensuring the directory is writable.
|
||||
chown -R root:root /var/www/data || true
|
||||
chmod -R a+rwX /var/www/data || true
|
||||
|
||||
# Run the initial speed test once (in background) to populate files if possible
|
||||
# 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"
|
||||
else
|
||||
(crontab -l 2>/dev/null; echo "$CRON_ENTRY") | crontab -
|
||||
echo "installed cron entry into root crontab"
|
||||
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"
|
||||
busybox httpd -f -p ${PORT} -h /var/www
|
||||
else
|
||||
echo "warning: busybox httpd not found; container will keep running with cron only" >&2
|
||||
# keep the script running so container doesn't exit
|
||||
tail -f /var/log/cron.log
|
||||
fi
|
||||
Reference in New Issue
Block a user