diff --git a/docker/Dockerfile b/docker/Dockerfile index bcc213e6..2fa290e5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -57,6 +57,12 @@ 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" \ +CRON_WRAPPER_SCRIPT="/config/.cron_wrapper" \ +LOGS_TO_STDOUT=/config/.cron.log \ +LSIO_FIRST_PARTY=false VOLUME /config \ No newline at end of file diff --git a/docker/Dockerfile.gui b/docker/Dockerfile.gui index 0b095a27..68752b17 100644 --- a/docker/Dockerfile.gui +++ b/docker/Dockerfile.gui @@ -79,11 +79,13 @@ 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" \ +CRON_WRAPPER_SCRIPT="/config/ytdl-sub-configs/.cron_wrapper" \ +LOGS_TO_STDOUT=/config/ytdl-sub-configs/.cron.log \ +LSIO_FIRST_PARTY=false VOLUME /config \ No newline at end of file diff --git a/docker/Dockerfile.ubuntu b/docker/Dockerfile.ubuntu index bef0f137..4f17af97 100644 --- a/docker/Dockerfile.ubuntu +++ b/docker/Dockerfile.ubuntu @@ -83,6 +83,12 @@ 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" \ +CRON_WRAPPER_SCRIPT="/config/.cron_wrapper" \ +LOGS_TO_STDOUT=/config/.cron.log \ +LSIO_FIRST_PARTY=false 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..3926dd4b --- /dev/null +++ b/docker/root/custom-cont-init.d/defaults @@ -0,0 +1,69 @@ +#!/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 -r /defaults/examples/* "$DEFAULT_WORKSPACE/examples" + +[[ ! -e "/config/.bashrc" ]] && \ + echo "alias ls='ls --color=auto'" > /config/.bashrc && \ + echo "cd ." >> /config/.bashrc + +# permissions +chown -R ${PUID:-abc}:${PGID:-abc} \ + /config + +# set up cron +if [ "$CRON_SCHEDULE" != "" ] ; then + [[ ! -e "$CRON_SCRIPT" ]] && \ + cp /defaults/cron "$CRON_SCRIPT" + + # create cron script wrapper + echo '#!/bin/bash' > "$CRON_WRAPPER_SCRIPT" + echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> "$CRON_WRAPPER_SCRIPT" + echo "cd \"$DEFAULT_WORKSPACE\"" >> "$CRON_WRAPPER_SCRIPT" + echo ". \"$CRON_SCRIPT\" | tee -a \"$LOGS_TO_STDOUT\"" >> "$CRON_WRAPPER_SCRIPT" + chmod +x "$CRON_WRAPPER_SCRIPT" + chown abc:abc "$CRON_WRAPPER_SCRIPT" + + # Set the crontab file to the schedule, cleanly + CRON_SCHEDULE_CLEAN="${CRON_SCHEDULE//\"/}" + CRON_SCHEDULE_CLEAN="${CRON_SCHEDULE_CLEAN//\'/}" + + echo "# min hour day month weekday command" > /config/crontabs/abc + echo "$CRON_SCHEDULE_CLEAN $DEFAULT_WORKSPACE/.cron_wrapper" >> /config/crontabs/abc + + chmod +x "$CRON_SCRIPT" + chown abc:abc "$CRON_SCRIPT" + + crontab -u abc /config/crontabs/abc + + CRON_SUCCESS=$? + if [ $CRON_SUCCESS -eq 0 ] ; 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" + 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 +fi + +# always create cron log file, after cron runs +# on start to not tail it again +echo "" > "$LOGS_TO_STDOUT" 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..6fdbea71 --- /dev/null +++ b/docker/root/defaults/cron @@ -0,0 +1,4 @@ +echo "Beginning cron job..." + +# Place your ytdl-sub command(s) here. +# This script is executed in the same relative path as this file. \ No newline at end of file diff --git a/docker/root/etc/s6-overlay/s6-rc.d/init-adduser/branding b/docker/root/etc/s6-overlay/s6-rc.d/init-adduser/branding new file mode 100644 index 00000000..0aaa4244 --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/init-adduser/branding @@ -0,0 +1,15 @@ +―――――――――――――――――――――――――――――――――――― +██╗ ██╗████████╗██████╗ ██╗ +╚██╗ ██╔╝╚══██╔══╝██╔══██╗██║ + ╚████╔╝ ██║ ██║ ██║██║ + ╚██╔╝ ██║ ██║ ██║██║ + ██║ ██║ ██████╔╝███████╗ + ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ + + ███████╗██╗ ██╗██████╗ + ██╔════╝██║ ██║██╔══██╗ + ███████╗██║ ██║██████╔╝ + ╚════██║██║ ██║██╔══██╗ + ███████║╚██████╔╝██████╔╝ + ╚══════╝ ╚═════╝ ╚═════╝ +―――――――――――――――――――――――――――――――――――― \ No newline at end of file diff --git a/docker/root/etc/s6-overlay/s6-rc.d/init-adduser/test.txt b/docker/root/etc/s6-overlay/s6-rc.d/init-adduser/test.txt new file mode 100644 index 00000000..32f95c0d --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/init-adduser/test.txt @@ -0,0 +1 @@ +hi \ No newline at end of file diff --git a/docker/testing/docker-compose.yml b/docker/testing/docker-compose.yml index 1a8797b9..432d0098 100644 --- a/docker/testing/docker-compose.yml +++ b/docker/testing/docker-compose.yml @@ -6,8 +6,34 @@ services: - PUID=1000 - PGID=1000 - TZ=America/Los_Angeles + - CRON_SCHEDULE="*/1 * * * *" + - CRON_RUN_ON_START=true volumes: - ./volumes/ytdl-sub-gui:/config ports: - 8443:8443 restart: unless-stopped + ytdl-sub: + image: ytdl-sub:local + container_name: ytdl-sub + environment: + - PUID=1000 + - PGID=1000 + - TZ=America/Los_Angeles + - CRON_SCHEDULE="*/1 * * * *" + - CRON_RUN_ON_START=true + volumes: + - ./volumes/ytdl-sub:/config + restart: unless-stopped + ytdl-sub-ubuntu: + image: ytdl-sub-ubuntu:local + container_name: ytdl-sub-ubuntu + environment: + - PUID=1000 + - PGID=1000 + - TZ=America/Los_Angeles + - CRON_SCHEDULE="*/1 * * * *" + - CRON_RUN_ON_START=true + volumes: + - ./volumes/ytdl-sub:/config + restart: unless-stopped diff --git a/docs/source/guides/getting_started/automating_downloads.rst b/docs/source/guides/getting_started/automating_downloads.rst index 9608a7b1..392c8ebb 100644 --- a/docs/source/guides/getting_started/automating_downloads.rst +++ b/docs/source/guides/getting_started/automating_downloads.rst @@ -1,133 +1,43 @@ Automating Downloads ==================== -One of the key capabilities of ``ytdl-sub`` automating new downloads. -To take advantage of this, you must set up scheduling to execute the commands at some interval. -How you set up this scheduling depends on which version of ``ytdl-sub`` you downloaded. - - :ref:`Guide for Docker and Unraid Containers ` :ref:`Guide for Linux ` :ref:`Guide for Windows ` -.. _cron tab manpage: https://man7.org/linux/man-pages/man5/crontab.5.html#EXAMPLE_CRON_FILE +.. _cron scheduling syntax: https://crontab.guru/#0_*/6_*_*_* .. _docker-unraid-setup: Docker and Unraid ----------------- -.. tab-set:: - - .. tab-item:: GUI Image - - The script that will execute automatically is located at ``/config/ytdl-sub-configs/run_cron``. +Cron is preconfigured in every ytdl-sub docker container. Enable by adding the following +ENV variables to your docker setup. - Access your container at http://localhost:8443/, then in the GUI terminal run these commands: +.. code-block:: yaml - .. code-block:: shell + services: + ytdl-sub: + environment: + - CRON_SCHEDULE="0 */6 * * *" + - CRON_RUN_ON_START=false - echo '#!/bin/bash' > /config/ytdl-sub-configs/run_cron - echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /config/ytdl-sub-configs/run_cron - echo "echo 'Cron started, running ytdl-sub...'" >> /config/ytdl-sub-configs/run_cron - echo "cd /config/ytdl-sub-configs" >> /config/ytdl-sub-configs/run_cron - echo "ytdl-sub --config=config.yaml sub subscriptions.yaml" >> /config/ytdl-sub-configs/run_cron - chmod +x /config/ytdl-sub-configs/run_cron - chown abc:abc /config/ytdl-sub-configs/run_cron - You can test the newly created script by running: +- ``CRON_SCHEDULE`` follows the standard `cron scheduling syntax`_. The above value will run the script once every 6 hours. +- ``CRON_RUN_ON_START`` toggles whether to run your cron script on container start. - .. code-block:: shell +The cron script will reside in the main directory with the file name ``cron``. +Cron logs should show when viewing the Docker logs. - /config/ytdl-sub-configs/run_cron - - To create the cron definition, run the following command: - - .. code-block:: shell - - echo "# min hour day month weekday command" > /config/crontabs/abc - echo " 0 */6 * * * /config/ytdl-sub-configs/run_cron" >> /config/crontabs/abc - - This will run the script every 6 hours. To run every hour, change ``*/6`` to ``*/1``, or to run once a day, change the same value to the hour (in 24hr format) that you want it to run at. See the `cron tab manpage`_ for more options. - - .. attention:: - The Docker container needs to be restarted for changes to take effect. Run `crontab -e` after to verify settings are correct. - - .. tab-item:: Headless Image - - .. _LinuxServer's Universal Cron mod: https://github.com/linuxserver/docker-mods/tree/universal-cron - - The first step is to ensure you have `LinuxServer's Universal Cron mod`_ enabled via the environment variable. For the GUI image, this is already included (no need to add it). - - .. code-block:: yaml - - services: - ytdl-sub: - image: ghcr.io/jmbannon/ytdl-sub:latest - container_name: ytdl-sub - environment: - - PUID=1000 - - PGID=1000 - - TZ=America/Los_Angeles - - DOCKER_MODS=linuxserver/mods:universal-cron # <-- Make sure you have this! - volumes: - # ensure directories have user permissions - - :/config - - :/tv_shows - restart: unless-stopped - - This line will tell your container to install and enable cron on start. - - If you had to add this line, you will need to restart your container. - - .. code-block:: shell - - docker compose restart - - The script that will execute automatically is located at ``/config/run_cron``. - - Access your container from the terminal by running: - - .. code-block:: shell - - docker exec -itu abc ytdl-sub /bin/bash - - then in the terminal run these commands: - - .. code-block:: shell - - echo '#!/bin/bash' > /config/run_cron - echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /config/run_cron - echo "echo 'Cron started, running ytdl-sub...'" >> /config/run_cron - echo "cd /config" >> /config/run_cron - echo "ytdl-sub --config=config.yaml sub subscriptions.yaml" >> /config/run_cron - chmod +x /config/run_cron - chown abc:abc /config/run_cron - - You can test the newly created script by running: - - .. code-block:: - - /config/run_cron - - To create the cron definition, run the following command: - - .. code-block:: shell - - echo "# min hour day month weekday command" > /config/crontabs/abc - echo " 0 */6 * * * /config/run_cron" >> /config/crontabs/abc - - This will run the script every 6 hours. To run every hour, change ``*/6`` to ``*/1``, or to run once a day, change the same value to the hour (in 24hr format) that you want it to run at. See the `cron tab manpage`_ for more options. - - .. attention:: - The Docker container needs to be restarted for changes to take effect. Run `crontab -e` after to verify settings are correct. .. _linux-setup: Linux ----- +Must configure crontab manually, like so: .. code-block:: shell diff --git a/docs/source/guides/install/docker.rst b/docs/source/guides/install/docker.rst index bf9b04c4..c2faa84a 100644 --- a/docs/source/guides/install/docker.rst +++ b/docs/source/guides/install/docker.rst @@ -79,7 +79,6 @@ Docker Compose is an easy "set it and forget it" install method. Follow the inst - PUID=1000 - PGID=1000 - TZ=America/Los_Angeles - - DOCKER_MODS=linuxserver/mods:universal-cron volumes: - :/config - :/tv_shows # optional