From e27a7c549537acebc3769d3d07dda76e2c615308 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Wed, 2 Apr 2025 21:22:12 -0700 Subject: [PATCH] [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 --- docker/root/custom-cont-init.d/defaults | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docker/root/custom-cont-init.d/defaults b/docker/root/custom-cont-init.d/defaults index e07ed6a8..cfbc0776 100644 --- a/docker/root/custom-cont-init.d/defaults +++ b/docker/root/custom-cont-init.d/defaults @@ -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"