From e9b5772dae614065ec670309da6bd6269a4b2cd1 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 11 Jan 2019 21:06:34 -0600 Subject: [PATCH] Allow configuration of user used for task execution New NEXTCLOUD_EXEC_USER environment variable added which allows control over which user is used to execute cron tasks inside the Nextcloud container. By default, the user is `www-data`. If the environment variable is specified but empty, no `--user` option is provided to `docker exec`. --- Dockerfile | 1 + README.md | 9 ++++++++- scripts/cron-tasks.sh | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 115dbd6..177e105 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM alpine RUN apk add --no-cache docker bash +ENV NEXTCLOUD_EXEC_USER=www-data ENV NEXTCLOUD_CONTAINER_NAME= ENV NEXTCLOUD_PROJECT_NAME= ENV NEXTCLOUD_CRON_MINUTE_INTERVAL=15 diff --git a/README.md b/README.md index ea76526..a195bcb 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,13 @@ entirely. * `NEXTCLOUD_CRON_MINUTE_INTERVAL`
The interval, in minutes, of how often the cron task executes. The default is 15 minutes. +* `NEXTCLOUD_EXEC_USER`
+ The user that should be used to run the cron tasks inside the Nextcloud container. This parameter + is specified to the `docker exec` command from this container. By default, the user used is + `www-data`, which is also the default user used inside Nextcloud, unless you've overridden it. You + may also define this environment variable to be blank (e.g. `NEXTCLOUD_EXEC_USER=`) which results + 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. # Container Health @@ -67,7 +74,7 @@ is checked every interval of the health check. If any of these checks fail, it i container's health status will become *unhealthy*. In this case, you should restart the container. 1. The `crond` process must be running. -1. The Nextcloud container must be available and running. One important note here: When this +2. The Nextcloud container must be available and running. One important note here: When this container starts up, it immediately searches for the container by name and remembers it by the container's ID. If for whatever reason the Nextcloud container changes in such a way that the ID is no longer valid, the health check would fail. diff --git a/scripts/cron-tasks.sh b/scripts/cron-tasks.sh index da1ca60..13ca88d 100755 --- a/scripts/cron-tasks.sh +++ b/scripts/cron-tasks.sh @@ -5,13 +5,19 @@ echo "-------------------------------------------------------------" echo " Executing Cron Tasks: $(date)" echo "-------------------------------------------------------------" +# If a user must be specified when executing the task, set up that option here. +# You may also leave NEXTCLOUD_EXEC_USER blank, in which case it will not be used. +if [[ -n "$NEXTCLOUD_EXEC_USER" ]]; then + exec_user="--user $NEXTCLOUD_EXEC_USER" +fi + # 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. cd /cron-scripts for script in *.sh; do echo "> Running Script: $script" - docker exec -i "$1" bash < $script + docker exec $exec_user -i "$1" bash < $script done echo "> Done"