[DOCKER] Fix various cron issues (#1204)

Closes
- https://github.com/jmbannon/ytdl-sub/issues/1200
  - Runs in the background now
- https://github.com/jmbannon/ytdl-sub/issues/1201
  - Was not running as user `abc`, now it is
- https://github.com/jmbannon/ytdl-sub/issues/1202
  - Due to reading stdout and tail of hidden log file. Should only tail from hidden log file now

Will leave crontab as-is if no CRON_SCHEDULE is specified
This commit is contained in:
Jesse Bannon 2025-04-02 21:22:12 -07:00 committed by GitHub
parent 6cf41a06b5
commit e27a7c5495
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,6 +21,9 @@ echo "Starting ytdl-sub..."
chown -R ${PUID:-abc}:${PGID:-abc} \
/config
# always create empty cron log file on start
echo "" > "$LOGS_TO_STDOUT"
# set up cron
if [ "$CRON_SCHEDULE" != "" ] ; then
[[ ! -e "$CRON_SCRIPT" ]] && \
@ -51,19 +54,15 @@ if [ "$CRON_SCHEDULE" != "" ] ; then
echo "Cron enabled with schedule $CRON_SCHEDULE_CLEAN"
if [ "$CRON_RUN_ON_START" = true ] ; then
echo "Running cron script on start"
. "$CRON_WRAPPER_SCRIPT"
echo "Running cron script on start in the background"
# ensure it runs as abc to respect puid/guid with delay for tail to start
su -s "/bin/bash" -c "sleep 5 && . '$CRON_WRAPPER_SCRIPT'" abc > /dev/null 2>&1 &
fi
else
echo "Error in CRON_SCHEDULE definition, disabling cron."
exit 1
fi
else
echo "CRON_SCHEDULE not specified, disabling cron."
echo "# min hour day month weekday command" > /config/crontabs/abc
echo "" >> /config/crontabs/abc
echo "CRON_SCHEDULE not specified, leaving crontabs as-is. Current configuration in /config/crontabs/abc"
cat /config/crontabs/abc
fi
# always create cron log file, after cron runs
# on start to not tail it again
echo "" > "$LOGS_TO_STDOUT"