plex-prerolls/entrypoint.sh

37 lines
958 B
Bash
Raw Normal View History

#!/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-09 01:06:35 +00:00
echo "Cron schedule: $CRON_SCHEDULE"
# 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"
# 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
# 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"
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"
crond && tail -f /var/log/cron.log