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.
This commit is contained in:
Robert Dailey 2020-10-27 16:45:16 -05:00
parent ff71477632
commit f2ce54653b
3 changed files with 7 additions and 4 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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() {