From fadb862b8a38ae9dde63e904d4a3632b7d1e4d09 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Sat, 8 Mar 2025 14:02:09 -0800 Subject: [PATCH] [DOCKER] Build cron into the container --- docker/Dockerfile | 6 +++- docker/Dockerfile.gui | 10 +++--- docker/Dockerfile.ubuntu | 6 +++- docker/root/custom-cont-init.d/defaults | 32 +++++++++++++++++++ docker/root/custom-cont-init.d/defaults-gui | 23 ------------- .../root/custom-cont-init.d/defaults-headless | 20 ------------ docker/root/defaults/cron | 4 +++ docker/root/defaults/cron_wrapper | 4 +++ 8 files changed, 55 insertions(+), 50 deletions(-) create mode 100644 docker/root/custom-cont-init.d/defaults delete mode 100644 docker/root/custom-cont-init.d/defaults-gui delete mode 100644 docker/root/custom-cont-init.d/defaults-headless create mode 100644 docker/root/defaults/cron create mode 100644 docker/root/defaults/cron_wrapper diff --git a/docker/Dockerfile b/docker/Dockerfile index bcc213e6..b69abbde 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -57,6 +57,10 @@ RUN mkdir -p /config && \ # CONTAINER CONFIGS ENV EDITOR="nano" \ -HOME="/config" +HOME="/config" \ +DOCKER_MODS=linuxserver/mods:universal-stdout-logs|linuxserver/mods:universal-cron \ +DEFAULT_WORKSPACE=/config \ +CRON_SCRIPT="/config/cron" \ +LOGS_TO_STDOUT=/config/.cron.log VOLUME /config \ No newline at end of file diff --git a/docker/Dockerfile.gui b/docker/Dockerfile.gui index 0b095a27..c6006540 100644 --- a/docker/Dockerfile.gui +++ b/docker/Dockerfile.gui @@ -79,11 +79,11 @@ RUN mkdir -p /config && \ ############################################################################### # CONTAINER CONFIGS - -ENV YTDL_SUB_TYPE="gui" \ -EDITOR="nano" \ +ENV EDITOR="nano" \ HOME="/config" \ -DOCKER_MODS=linuxserver/mods:universal-cron \ -DEFAULT_WORKSPACE=/config/ytdl-sub-configs +DOCKER_MODS=linuxserver/mods:universal-stdout-logs|linuxserver/mods:universal-cron \ +DEFAULT_WORKSPACE=/config/ytdl-sub-configs \ +CRON_SCRIPT="/config/ytdl-sub-configs/cron" \ +LOGS_TO_STDOUT=/config/ytdl-sub-configs/.cron.log VOLUME /config \ No newline at end of file diff --git a/docker/Dockerfile.ubuntu b/docker/Dockerfile.ubuntu index bef0f137..b42c3daf 100644 --- a/docker/Dockerfile.ubuntu +++ b/docker/Dockerfile.ubuntu @@ -83,6 +83,10 @@ RUN mkdir -p /config && \ # CONTAINER CONFIGS ENV EDITOR="nano" \ -HOME="/config" +HOME="/config" \ +DOCKER_MODS=linuxserver/mods:universal-stdout-logs|linuxserver/mods:universal-cron \ +DEFAULT_WORKSPACE=/config \ +CRON_SCRIPT="/config/cron" \ +LOGS_TO_STDOUT=/config/.cron.log VOLUME /config \ No newline at end of file diff --git a/docker/root/custom-cont-init.d/defaults b/docker/root/custom-cont-init.d/defaults new file mode 100644 index 00000000..34f71316 --- /dev/null +++ b/docker/root/custom-cont-init.d/defaults @@ -0,0 +1,32 @@ +#!/usr/bin/with-contenv bash + +echo "Starting ytdl-sub..." + +# copy config +[[ ! -e "$DEFAULT_WORKSPACE/config.yaml" ]] && \ + mkdir -p "$DEFAULT_WORKSPACE" && \ + cp /defaults/config.yaml "$DEFAULT_WORKSPACE/config.yaml" +[[ ! -e "$DEFAULT_WORKSPACE/subscriptions.yaml" ]] && \ + mkdir -p "$DEFAULT_WORKSPACE" && \ + cp /defaults/subscriptions.yaml "$DEFAULT_WORKSPACE/subscriptions.yaml" +[[ ! -d "$DEFAULT_WORKSPACE/examples" ]] && \ + mkdir -p "$DEFAULT_WORKSPACE/examples" && \ + cp /defaults/examples/* "$DEFAULT_WORKSPACE/examples" + +# permissions +chown -R ${PUID:-abc}:${PGID:-abc} \ + /config + +# set up cron +if [ "$CRON_SCHEDULE" != "" ] ; then + [[ ! -e "$CRON_SCRIPT" ]] && \ + cp /defaults/cron "$CRON_SCRIPT" + + cp /defaults/cron_wrapper "$DEFAULT_WORKSPACE/.cron_wrapper" + + echo "# min hour day month weekday command" > /config/crontabs/abc + echo "$CRON_SCHEDULE $DEFAULT_WORKSPACE/.cron_wrapper" >> /config/crontabs/abc + + chmod +x "$CRON_SCRIPT" + chown abc:abc "$CRON_SCRIPT" +fi \ No newline at end of file diff --git a/docker/root/custom-cont-init.d/defaults-gui b/docker/root/custom-cont-init.d/defaults-gui deleted file mode 100644 index 01affd47..00000000 --- a/docker/root/custom-cont-init.d/defaults-gui +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/with-contenv bash - -# Exit if not gui -if [ "$YTDL_SUB_TYPE" != "gui" ] ; then - exit 0 -fi - -echo "Checking ytdl-sub-gui defaults..." - -# copy config -[[ ! -e /config/ytdl-sub-configs/config.yaml ]] && \ - mkdir -p /config/ytdl-sub-configs && \ - cp /defaults/config.yaml /config/ytdl-sub-configs/config.yaml -[[ ! -e /config/ytdl-sub-configs/subscriptions.yaml ]] && \ - mkdir -p /config/ytdl-sub-configs && \ - cp /defaults/subscriptions.yaml /config/ytdl-sub-configs/subscriptions.yaml -[[ ! -d /config/ytdl-sub-configs/examples ]] && \ - mkdir -p /config/ytdl-sub-configs/examples && \ - cp /defaults/examples/* /config/ytdl-sub-configs/examples - -# permissions -chown -R ${PUID:-abc}:${PGID:-abc} \ - /config diff --git a/docker/root/custom-cont-init.d/defaults-headless b/docker/root/custom-cont-init.d/defaults-headless deleted file mode 100644 index 8d5d632b..00000000 --- a/docker/root/custom-cont-init.d/defaults-headless +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/with-contenv bash - -# Exit if gui -if [ "$YTDL_SUB_TYPE" == "gui" ] ; then - exit 0 -fi - -echo "Checking ytdl-sub defaults..." - -# copy config -[[ ! -e /config/config.yaml ]] && \ - cp /defaults/config.yaml /config/config.yaml -[[ ! -e /config/subscriptions.yaml ]] && \ - cp /defaults/subscriptions.yaml /config/subscriptions.yaml -[[ ! -d /config/examples ]] && \ - cp -R /defaults/examples /config/ - -# permissions -chown -R ${PUID:-abc}:${PGID:-abc} \ - /config \ No newline at end of file diff --git a/docker/root/defaults/cron b/docker/root/defaults/cron new file mode 100644 index 00000000..20690777 --- /dev/null +++ b/docker/root/defaults/cron @@ -0,0 +1,4 @@ +echo "Beginning cron job..." + +# Place your ytdl-sub command here +# ytdl-sub -h \ No newline at end of file diff --git a/docker/root/defaults/cron_wrapper b/docker/root/defaults/cron_wrapper new file mode 100644 index 00000000..150b6799 --- /dev/null +++ b/docker/root/defaults/cron_wrapper @@ -0,0 +1,4 @@ +#!/bin/bash +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +. "$CRON_SCRIPT" | tee "$LOGS_TO_STDOUT" \ No newline at end of file