From 08ec92f509fe35836d40446ed0b4835e2aac1d90 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 28 Aug 2020 14:45:17 -0500 Subject: [PATCH] Add extra logs and debugging features * New DEBUG environment variable enables `set -x` in shell scripts for extra verbose output for debugging custom cron scripts and to assist with development of the core scripts. * Verify if we can find the Nextcloud container on start up. Fail if not. * Print information about how we will search for Nextcloud on start up. * During cron task execution, the ID of the Nextcloud container is printed, if found. --- README.md | 4 ++++ scripts/cron-tasks.sh | 3 +++ scripts/entrypoint.sh | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/README.md b/README.md index f214362..e5169ff 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,10 @@ how this all works. in the tasks being executed using the Nextcloud container's running user. Specifically, the `--user` option will *not* be provided to the `docker exec` command. +* `DEBUG`
+ Enables more verbose logging in core scripts. Useful only for development. To get more verbose + output in your own custom cron scripts, use `set -x` in the actual script. + ## Container Health If you do `docker-compose ps`, you will see the active health of the container. The following logic diff --git a/scripts/cron-tasks.sh b/scripts/cron-tasks.sh index f10fe18..e4c886b 100755 --- a/scripts/cron-tasks.sh +++ b/scripts/cron-tasks.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +[[ ! -z "$DEBUG" ]] && set -x echo "-------------------------------------------------------------" echo " Executing Cron Tasks: $(date)" @@ -20,6 +21,8 @@ if [[ -z "$containerId" ]]; then exit 1 fi +echo "> Nextcloud Container ID: ${containerId}" + # Loop through all shell scripts and execute the contents of those scripts in the Nextcloud # container. It's done this way so that the user may mount more scripts to be executed in addition # to the default ones. diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index d2a23e1..6351879 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,11 +1,29 @@ #!/usr/bin/env bash set -e +[[ ! -z "$DEBUG" ]] && set -x if [[ -z "$NEXTCLOUD_CONTAINER_NAME" ]]; then echo "NEXTCLOUD_CONTAINER_NAME is a required variable" exit 1 fi +# Print info about how we will look for Nextcloud +if [[ -n "$NEXTCLOUD_PROJECT_NAME" ]]; then + echo "Will search for Nexcloud container as a Docker Compose service" + echo "Project: $NEXTCLOUD_PROJECT_NAME, Service: $NEXTCLOUD_CONTAINER_NAME" +else + echo "Container Name: $NEXTCLOUD_CONTAINER_NAME" +fi + +# Do an initial search for the container to rule out any configuration problems +containerId="$(/find-container.sh)" +if [[ -z "$containerId" ]]; then + echo "ERROR: Unable to find the Nextcloud container" + exit 1 +else + echo "Found Nextcloud container with ID $containerId" +fi + echo "*/$NEXTCLOUD_CRON_MINUTE_INTERVAL * * * * /cron-tasks.sh" \ > /var/spool/cron/crontabs/root