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`.
This commit is contained in:
Robert Dailey 2019-01-11 21:06:34 -06:00
parent 990ee018d2
commit e9b5772dae
No known key found for this signature in database
GPG key ID: 97751323F0627314
3 changed files with 16 additions and 2 deletions

View file

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

View file

@ -59,6 +59,13 @@ entirely.
* `NEXTCLOUD_CRON_MINUTE_INTERVAL`<br>
The interval, in minutes, of how often the cron task
executes. The default is 15 minutes.
* `NEXTCLOUD_EXEC_USER`<br>
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.

View file

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