From: Alex Pooley (@zuedev) Date: Mon, 23 Mar 2026 10:42:08 +0000 (+0000) Subject: add minutely cron job script X-Git-Url: http://git.zue.dev/?a=commitdiff_plain;h=be2555d95dfaf3f214a21cc72d3834119069fff4;p=git.zue.dev add minutely cron job script --- diff --git a/cron/minutely.sh b/cron/minutely.sh new file mode 100644 index 0000000..87633d8 --- /dev/null +++ b/cron/minutely.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +GIT_ZUE_DEV="/home/git/git.zue.dev/" +DOCKER_COMPOSE_DIRECTORY="/root/" +DOCKER_COMPOSE_FILENAME="docker-compose.yaml" + +echo "This is a minutely cron job. Current time: $(date)" + +# do we have the repo? +if [ -z "$GIT_ZUE_DEV" ]; then + echo "Repository not found. PANIC!" + exit 1 +fi + +# enter the repo +cd "$GIT_ZUE_DEV" || { echo "Failed to change directory to $GIT_ZUE_DEV. PANIC!"; exit 1; } + +# can we see the docker-compose.yaml file in the repo? +git cat-file HEAD:"$DOCKER_COMPOSE_FILENAME" > /dev/null 2>&1 || { echo "$DOCKER_COMPOSE_FILENAME not found in the repository. PANIC!"; exit 1; } + +# compare our local copy of the docker-compose.yaml with the one in the repo +if ! git diff --quiet HEAD:"$DOCKER_COMPOSE_FILENAME" "$DOCKER_COMPOSE_DIRECTORY/$DOCKER_COMPOSE_FILENAME"; then + echo "$DOCKER_COMPOSE_FILENAME has changed. Updating local copy..." + git show HEAD:"$DOCKER_COMPOSE_FILENAME" > "$DOCKER_COMPOSE_DIRECTORY/$DOCKER_COMPOSE_FILENAME" + + # then rebuild the containers + echo "Rebuilding Docker containers..." + cd "$DOCKER_COMPOSE_DIRECTORY" || { echo "Failed to change directory to $DOCKER_COMPOSE_DIRECTORY. PANIC!"; exit 1; } + + docker compose down + docker compose build + docker compose up -d +else + echo "$DOCKER_COMPOSE_FILENAME has not changed. No action needed." +fi + +echo "Minutely cron job completed." \ No newline at end of file