From f2ce54653b6f8092da1e3abfd25179a4c7c68e0b Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Tue, 27 Oct 2020 16:45:16 -0500 Subject: [PATCH] Fix various custom script processing issues The following issues were addressed. Note that these are edge cases. * If an empty `/cron-scripts` directory was mounted in the container, an error would occur. * If files in the `/cron-scripts` directory had spaces in the name, this would cause issues. * stdin was held open when running `docker exec` which would cause hangs and other issues. The `exec` command is now run non-interactively. * Custom scripts that failed would interrupt processing of scripts after it, if any. --- README.md | 2 ++ scripts/cron-tasks.sh | 7 ++++--- scripts/nextcloud-exec.sh | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d8e17b3..b0fe344 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,8 @@ above. However, it is explicitly specified for example purposes. * All cron task shell scripts run at the same interval defined by `NEXTCLOUD_CRON_MINUTE_INTERVAL`. * Modification of your own shell scripts on the host do not require that you restart/recreate the container (only when volume mappings change in the YAML file). +* If a custom script in the `/cron-scripts` directory fails, it will not impede the processing of + other scripts in the directory. ## Debugging diff --git a/scripts/cron-tasks.sh b/scripts/cron-tasks.sh index c4d9c9e..aaf188a 100755 --- a/scripts/cron-tasks.sh +++ b/scripts/cron-tasks.sh @@ -21,9 +21,10 @@ echo "> Nextcloud Container ID: ${containerId}" run_scripts_in_dir() { cd "$1" - for script in *.sh; do - echo "> Running Script: $script" - nextcloud_exec "$containerId" "$(< $script)" + find . -type f -name '*.sh' -print0 | + while IFS= read -r -d '' file; do + echo "> Running Script: $file" + nextcloud_exec "$containerId" "$(cat $file)" || continue done } diff --git a/scripts/nextcloud-exec.sh b/scripts/nextcloud-exec.sh index a6d978f..0ed574e 100644 --- a/scripts/nextcloud-exec.sh +++ b/scripts/nextcloud-exec.sh @@ -9,7 +9,7 @@ nextcloud_exec_no_shell() { exec_user="--user $NEXTCLOUD_EXEC_USER" fi - docker exec $exec_user -i "$containerId" "$@" + docker exec $exec_user "$containerId" "$@" } nextcloud_exec() {