Initial implementation of the nextcloud cronjob docker image

This commit is contained in:
Robert Dailey 2018-12-01 19:08:31 -06:00
parent 632211b91e
commit 04a4297164
5 changed files with 66 additions and 0 deletions

14
Dockerfile Normal file
View file

@ -0,0 +1,14 @@
FROM alpine
RUN apk add --no-cache docker bash
ENV NEXTCLOUD_CONTAINER_NAME=
ENV NEXTCLOUD_PROJECT_NAME=
ENV NEXTCLOUD_CRON_MINUTE_INTERVAL=15
COPY scripts/*.sh /
ENTRYPOINT ["/entrypoint.sh"]
HEALTHCHECK --timeout=5s \
CMD ["/healthcheck.sh"]

5
scripts/cron-tasks.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -ex
containerName="$1"
docker exec "$containerName" php -f /var/www/html/cron.php

30
scripts/entrypoint.sh Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -ex
if [[ -z "$NEXTCLOUD_CONTAINER_NAME" ]]; then
echo "NEXTCLOUD_CONTAINER_NAME is a required variable"
exit 1
fi
if [[ ! -z "$NEXTCLOUD_PROJECT_NAME" ]]; then
containerName="${NEXTCLOUD_PROJECT_NAME}_"
else
matchEnd=","
fi
containerName="${containerName}${NEXTCLOUD_CONTAINER_NAME}"
# Get the ID of the container so we can exec something in it later
export containerId=$(/find-container.sh "$containerName" "$matchEnd")
if [[ -z "$containerId" ]]; then
echo "ERROR: Unable to find the Nextcloud container"
exit 1
fi
echo "$containerId" > /tmp/containerId
echo "*/$NEXTCLOUD_CRON_MINUTE_INTERVAL * * * * /cron-tasks.sh $containerId" \
> /var/spool/cron/crontabs/root
exec crond -f -l 0 -L /dev/stdout

9
scripts/find-container.sh Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
containerName="$1"
matchEnd="$2"
docker ps --format '{{.Names}},{{.ID}}' | \
egrep "^${containerName}${matchEnd}" | \
awk '{split($0,a,","); print a[2]}'

8
scripts/healthcheck.sh Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -x
# Make sure cron daemon is still running
ps -o comm | grep crond || exit 1
# Make sure the target container is still running/available
docker inspect -f '{{.State.Running}}' "$(cat /tmp/containerId)" | grep true || exit 1