From 860b518c74f8f29d29cb25eb471a9cabf84ec655 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Sun, 30 Jul 2023 01:15:12 -0500 Subject: [PATCH 1/5] standard cron Signed-off-by: Eric Nemchik --- README.md | 4 ++-- .../s6-rc.d/init-mod-universal-cron-add-package/run | 8 +++++--- .../s6-rc.d/init-mod-universal-cron-setup/up | 1 - .../dependencies.d/init-mods-package-install | 0 .../run | 0 .../type | 0 .../s6-rc.d/init-mod-universal-crontab-config/up | 1 + ...al-cron-setup => init-mod-universal-crontab-config} | 0 .../dependencies.d/init-services | 0 root/etc/s6-overlay/s6-rc.d/svc-cron/run | 10 ++++++++++ .../s6-rc.d/{svc-mod-universal-cron => svc-cron}/type | 0 root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/run | 10 ---------- ...al-cron-setup => init-mod-universal-crontab-config} | 0 .../contents.d/{svc-mod-universal-cron => svc-cron} | 0 14 files changed, 18 insertions(+), 16 deletions(-) delete mode 100644 root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/up rename root/etc/s6-overlay/s6-rc.d/{init-mod-universal-cron-setup => init-mod-universal-crontab-config}/dependencies.d/init-mods-package-install (100%) rename root/etc/s6-overlay/s6-rc.d/{init-mod-universal-cron-setup => init-mod-universal-crontab-config}/run (100%) mode change 100755 => 100644 rename root/etc/s6-overlay/s6-rc.d/{init-mod-universal-cron-setup => init-mod-universal-crontab-config}/type (100%) create mode 100644 root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/up rename root/etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/{init-mod-universal-cron-setup => init-mod-universal-crontab-config} (100%) rename root/etc/s6-overlay/s6-rc.d/{svc-mod-universal-cron => svc-cron}/dependencies.d/init-services (100%) create mode 100644 root/etc/s6-overlay/s6-rc.d/svc-cron/run rename root/etc/s6-overlay/s6-rc.d/{svc-mod-universal-cron => svc-cron}/type (100%) delete mode 100755 root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/run rename root/etc/s6-overlay/s6-rc.d/user/contents.d/{init-mod-universal-cron-setup => init-mod-universal-crontab-config} (100%) rename root/etc/s6-overlay/s6-rc.d/user/contents.d/{svc-mod-universal-cron => svc-cron} (100%) diff --git a/README.md b/README.md index 2fc615c..4a821b2 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ In any container docker arguments, set an environment variable `DOCKER_MODS=linu If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:universal-cron|linuxserver/mods:universal-mod2` -This mod will ensure you have `/config/crontabs/root` and `/config/crontabs/abc` files where you can add cron jobs to run inside the container as root or as the abc user (associated with the PUID/PGID environment variables). +This mod will ensure you have a `/config/crontabs/abc` file where you can add cron jobs to run inside the container as the abc user (associated with the PUID/PGID environment variables). No cron jobs (aside from what may be included in the base OS) are included by default. -You can test to confirm things are working by adding the following line to `/config/crontabs/root` or `/config/crontabs/abc` +You can test to confirm things are working by adding the following line to `/config/crontabs/abc` ```cron */5 * * * * /bin/echo test >> /config/tmp.txt diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run index 2d07fce..ff35c59 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run +++ b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run @@ -1,9 +1,11 @@ #!/usr/bin/with-contenv bash # shellcheck shell=bash -if [ ! -f /usr/sbin/cron ] && [ -f /usr/bin/apt ]; then +if ! builtin command -v busybox >/dev/null; then + echo "**** Adding busybox to package install list ****" + echo "busybox" >>/mod-repo-packages-to-install.list +fi +if [[ -f /usr/bin/apt ]] && [[ ! -f /usr/sbin/cron ]]; then echo "**** Adding cron to package install list ****" echo "cron" >>/mod-repo-packages-to-install.list -else - echo "**** cron package already installed, skipping ****" fi diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/up b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/up deleted file mode 100644 index b9dabf7..0000000 --- a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/up +++ /dev/null @@ -1 +0,0 @@ -/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/run \ No newline at end of file diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/dependencies.d/init-mods-package-install b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/dependencies.d/init-mods-package-install similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/dependencies.d/init-mods-package-install rename to root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/dependencies.d/init-mods-package-install diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/run b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run old mode 100755 new mode 100644 similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/run rename to root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/type b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/type similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-setup/type rename to root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/type diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/up b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/up new file mode 100644 index 0000000..3d8d756 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run \ No newline at end of file diff --git a/root/etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/init-mod-universal-cron-setup b/root/etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/init-mod-universal-crontab-config similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/init-mod-universal-cron-setup rename to root/etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/init-mod-universal-crontab-config diff --git a/root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/dependencies.d/init-services b/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-services similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/dependencies.d/init-services rename to root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-services diff --git a/root/etc/s6-overlay/s6-rc.d/svc-cron/run b/root/etc/s6-overlay/s6-rc.d/svc-cron/run new file mode 100644 index 0000000..f116b80 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-cron/run @@ -0,0 +1,10 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +if builtin command -v busybox >/dev/null && [[ $(busybox) =~ [[:space:]](crond)([,]|$) ]]; then + exec busybox crond -f -S -l 5 +elif [[ -f /usr/bin/apt ]] && [[ -f /usr/sbin/cron ]]; then + exec /usr/sbin/cron -f -L 5 +else + echo "**** cron not found ****" +fi diff --git a/root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/type b/root/etc/s6-overlay/s6-rc.d/svc-cron/type similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/type rename to root/etc/s6-overlay/s6-rc.d/svc-cron/type diff --git a/root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/run b/root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/run deleted file mode 100755 index 6f74396..0000000 --- a/root/etc/s6-overlay/s6-rc.d/svc-mod-universal-cron/run +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash - -if [ -f /usr/bin/apt ]; then - # ubuntu - exec /usr/sbin/cron -f -L 1 -elif [ -f /sbin/apk ]; then - # alpine - exec /usr/sbin/crond -f -S -l 5 -fi diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mod-universal-cron-setup b/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mod-universal-crontab-config similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mod-universal-cron-setup rename to root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mod-universal-crontab-config diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-mod-universal-cron b/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-cron similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-mod-universal-cron rename to root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-cron From 085f7a15f6e153d3156ba5ce66c88f1de8f8d553 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Sun, 30 Jul 2023 09:49:38 -0500 Subject: [PATCH 2/5] Fix perms Signed-off-by: Eric Nemchik --- root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run | 0 root/etc/s6-overlay/s6-rc.d/svc-cron/run | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run mode change 100644 => 100755 root/etc/s6-overlay/s6-rc.d/svc-cron/run diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run old mode 100644 new mode 100755 diff --git a/root/etc/s6-overlay/s6-rc.d/svc-cron/run b/root/etc/s6-overlay/s6-rc.d/svc-cron/run old mode 100644 new mode 100755 From b99571171606e4090427a845feed506631110a16 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Fri, 18 Aug 2023 23:07:16 -0500 Subject: [PATCH 3/5] cron in base Signed-off-by: Eric Nemchik --- .../init-mod-universal-cron-add-package/run | 11 ---- .../init-mod-universal-cron-add-package/type | 1 - .../init-mod-universal-cron-add-package/up | 1 - .../dependencies.d/init-mods | 0 .../dependencies.d/init-mods-package-install | 0 .../init-mod-universal-crontab-config/run | 56 ++++++++----------- .../init-mod-universal-cron-add-package | 0 .../svc-cron/dependencies.d/init-services | 0 root/etc/s6-overlay/s6-rc.d/svc-cron/run | 10 ---- root/etc/s6-overlay/s6-rc.d/svc-cron/type | 1 - .../init-mod-universal-cron-add-package | 0 .../s6-rc.d/user/contents.d/svc-cron | 0 12 files changed, 24 insertions(+), 56 deletions(-) delete mode 100755 root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run delete mode 100644 root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/type delete mode 100644 root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/up rename root/etc/s6-overlay/s6-rc.d/{init-mod-universal-cron-add-package => init-mod-universal-crontab-config}/dependencies.d/init-mods (100%) delete mode 100644 root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/dependencies.d/init-mods-package-install delete mode 100644 root/etc/s6-overlay/s6-rc.d/init-mods-package-install/dependencies.d/init-mod-universal-cron-add-package delete mode 100644 root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-services delete mode 100755 root/etc/s6-overlay/s6-rc.d/svc-cron/run delete mode 100644 root/etc/s6-overlay/s6-rc.d/svc-cron/type delete mode 100644 root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mod-universal-cron-add-package delete mode 100644 root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-cron diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run deleted file mode 100755 index ff35c59..0000000 --- a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash - -if ! builtin command -v busybox >/dev/null; then - echo "**** Adding busybox to package install list ****" - echo "busybox" >>/mod-repo-packages-to-install.list -fi -if [[ -f /usr/bin/apt ]] && [[ ! -f /usr/sbin/cron ]]; then - echo "**** Adding cron to package install list ****" - echo "cron" >>/mod-repo-packages-to-install.list -fi diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/type b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/type deleted file mode 100644 index 3d92b15..0000000 --- a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/type +++ /dev/null @@ -1 +0,0 @@ -oneshot \ No newline at end of file diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/up b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/up deleted file mode 100644 index f29dc41..0000000 --- a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/up +++ /dev/null @@ -1 +0,0 @@ -/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/run \ No newline at end of file diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/dependencies.d/init-mods b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/dependencies.d/init-mods similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/init-mod-universal-cron-add-package/dependencies.d/init-mods rename to root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/dependencies.d/init-mods diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/dependencies.d/init-mods-package-install b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/dependencies.d/init-mods-package-install deleted file mode 100644 index e69de29..0000000 diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run index 884068f..9c26f40 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run @@ -1,38 +1,30 @@ #!/usr/bin/with-contenv bash # shellcheck shell=bash -# make folders -mkdir -p \ - /config/crontabs +for cron_user in abc root; do + # make folders + mkdir -p \ + /config/crontabs -## root -# if crontabs do not exist in config -if [[ ! -f /config/crontabs/root ]]; then - # copy crontab from system - if crontab -l -u root; then - crontab -l -u root >/config/crontabs/root + # if crontabs do not exist in config + if [[ ! -f "/config/crontabs/${cron_user}" ]]; then + # copy crontab from system + if crontab -l -u "${cron_user}" >/dev/null; then + crontab -l -u "${cron_user}" >"/config/crontabs/${cron_user}" + fi + + if [[ -f "/defaults/crontabs/${cron_user}" ]]; then + # if crontabs still do not exist in config (were not copied from system) + # copy crontab from image defaults (using -n, do not overwrite an existing file) + cp -n "/defaults/crontabs/${cron_user}" /config/crontabs/ + fi + + # if crontabs still do not exist in config (were not copied from system) + # copy crontab from mod defaults (using -n, do not overwrite an existing file) + cp -n "/defaults/crontabs-mod/${cron_user}" /config/crontabs/ fi - # if crontabs still do not exist in config (were not copied from system) - # copy crontab from included defaults (using -n, do not overwrite an existing file) - cp -n /defaults/crontabs-mod/root /config/crontabs/ -fi -# set permissions and import user crontabs -lsiown root:root /config/crontabs/root -crontab -u root /config/crontabs/root - -## abc -# if crontabs do not exist in config -if [[ ! -f /config/crontabs/abc ]]; then - # copy crontab from system - if crontab -l -u abc; then - crontab -l -u abc >/config/crontabs/abc - fi - - # if crontabs still do not exist in config (were not copied from system) - # copy crontab from included defaults (using -n, do not overwrite an existing file) - cp -n /defaults/crontabs-mod/abc /config/crontabs/ -fi -# set permissions and import user crontabs -lsiown abc:abc /config/crontabs/abc -crontab -u abc /config/crontabs/abc + # set permissions and import user crontabs + lsiown "${cron_user}":"${cron_user}" "/config/crontabs/${cron_user}" + crontab -u "${cron_user}" "/config/crontabs/${cron_user}" +done diff --git a/root/etc/s6-overlay/s6-rc.d/init-mods-package-install/dependencies.d/init-mod-universal-cron-add-package b/root/etc/s6-overlay/s6-rc.d/init-mods-package-install/dependencies.d/init-mod-universal-cron-add-package deleted file mode 100644 index e69de29..0000000 diff --git a/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-services b/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-services deleted file mode 100644 index e69de29..0000000 diff --git a/root/etc/s6-overlay/s6-rc.d/svc-cron/run b/root/etc/s6-overlay/s6-rc.d/svc-cron/run deleted file mode 100755 index f116b80..0000000 --- a/root/etc/s6-overlay/s6-rc.d/svc-cron/run +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/with-contenv bash -# shellcheck shell=bash - -if builtin command -v busybox >/dev/null && [[ $(busybox) =~ [[:space:]](crond)([,]|$) ]]; then - exec busybox crond -f -S -l 5 -elif [[ -f /usr/bin/apt ]] && [[ -f /usr/sbin/cron ]]; then - exec /usr/sbin/cron -f -L 5 -else - echo "**** cron not found ****" -fi diff --git a/root/etc/s6-overlay/s6-rc.d/svc-cron/type b/root/etc/s6-overlay/s6-rc.d/svc-cron/type deleted file mode 100644 index 1780f9f..0000000 --- a/root/etc/s6-overlay/s6-rc.d/svc-cron/type +++ /dev/null @@ -1 +0,0 @@ -longrun \ No newline at end of file diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mod-universal-cron-add-package b/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mod-universal-cron-add-package deleted file mode 100644 index e69de29..0000000 diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-cron b/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-cron deleted file mode 100644 index e69de29..0000000 From 939dba834594566ac4840a002569d0b05542d7cc Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Sat, 26 Aug 2023 13:06:44 -0500 Subject: [PATCH 4/5] Revert README wording Signed-off-by: Eric Nemchik --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a821b2..2fc615c 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ In any container docker arguments, set an environment variable `DOCKER_MODS=linu If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:universal-cron|linuxserver/mods:universal-mod2` -This mod will ensure you have a `/config/crontabs/abc` file where you can add cron jobs to run inside the container as the abc user (associated with the PUID/PGID environment variables). +This mod will ensure you have `/config/crontabs/root` and `/config/crontabs/abc` files where you can add cron jobs to run inside the container as root or as the abc user (associated with the PUID/PGID environment variables). No cron jobs (aside from what may be included in the base OS) are included by default. -You can test to confirm things are working by adding the following line to `/config/crontabs/abc` +You can test to confirm things are working by adding the following line to `/config/crontabs/root` or `/config/crontabs/abc` ```cron */5 * * * * /bin/echo test >> /config/tmp.txt From c89a73d4d7e721599f33be4a72599abb12ac47c5 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 2 Nov 2023 13:11:50 -0500 Subject: [PATCH 5/5] Redirect stderr from cron --- .../s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run index 9c26f40..4275fbc 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-mod-universal-crontab-config/run @@ -9,7 +9,7 @@ for cron_user in abc root; do # if crontabs do not exist in config if [[ ! -f "/config/crontabs/${cron_user}" ]]; then # copy crontab from system - if crontab -l -u "${cron_user}" >/dev/null; then + if crontab -l -u "${cron_user}" >/dev/null 2>&1; then crontab -l -u "${cron_user}" >"/config/crontabs/${cron_user}" fi