nextcloud-cronjob/scripts/entrypoint.sh
Robert Dailey ab6372fa79 Provide the ability to run user-defined cron tasks
Mount individual shell scripts (with the `*.sh` extension) inside `/cron-scripts/` in the
container. The cron daemon will automatically run these scripts inside the Nextcloud
container for you. Write the scripts as if they will run in the Nextcloud container
itself.
2018-12-06 17:58:26 -06:00

31 lines
761 B
Bash
Executable file

#!/usr/bin/env bash
set -e
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