2023-12-08 01:57:30 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Create cron directory
|
|
|
|
mkdir -p /etc/cron.d
|
|
|
|
|
|
|
|
# Read cron schedule from environment variable
|
2023-12-09 08:23:26 +00:00
|
|
|
CRON_SCHEDULE=${CRON_SCHEDULE:-"0 0 * * *"} # Default to midnight every day if not supplied
|
2023-12-08 01:57:30 +00:00
|
|
|
|
2023-12-09 01:06:35 +00:00
|
|
|
echo "Cron schedule: $CRON_SCHEDULE"
|
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
# Add "--dry-run" flag if DRY_RUN is set to true
|
|
|
|
if [ "$DRY_RUN" = "true" ]; then
|
|
|
|
DRY_RUN_FLAG="--dry-run"
|
|
|
|
else
|
|
|
|
DRY_RUN_FLAG=""
|
|
|
|
fi
|
|
|
|
|
2023-12-09 01:06:35 +00:00
|
|
|
echo "Dry run flag: $DRY_RUN_FLAG"
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
# Schedule cron job with supplied cron schedule
|
2023-12-09 01:06:35 +00:00
|
|
|
echo "Scheduling cron job"
|
2023-12-09 08:05:13 +00:00
|
|
|
echo "$CRON_SCHEDULE python3 /run.py -c /config/config.yaml -l /logs $DRY_RUN_FLAG > /proc/1/fd/1 2>/proc/1/fd/2" > /etc/cron.d/schedule_preroll
|
2023-12-08 01:57:30 +00:00
|
|
|
|
|
|
|
# Give execution rights on the cron job
|
|
|
|
chmod 0644 /etc/cron.d/schedule_preroll
|
|
|
|
|
|
|
|
# Apply cron job
|
2023-12-09 01:06:35 +00:00
|
|
|
echo "Applying cron job"
|
2023-12-08 01:57:30 +00:00
|
|
|
crontab /etc/cron.d/schedule_preroll
|
|
|
|
|
|
|
|
# Create the log file to be able to run tail
|
|
|
|
touch /var/log/cron.log
|
|
|
|
|
|
|
|
# Run the command on container startup
|
2023-12-09 01:06:35 +00:00
|
|
|
echo "Starting cron"
|
2023-12-08 01:57:30 +00:00
|
|
|
crond && tail -f /var/log/cron.log
|