#!/bin/bash # {{ ansible_managed }} # Nextcloud "{{ cron_name }}" background jobs (cron.php). # # backgroundjobs_mode is "cron" on both instances, which means Nextcloud # expects an external caller to run cron.php every ~5 minutes. Nothing was: # the personal instance had not run a background job since 2026-05-14 and # skudak since 2024-11-20. Without it Nextcloud never expires trash or file # versions, never cleans stale chunked uploads, never sends calendar # reminders, and -- easy to miss -- never rotates nextcloud.log, which makes # the log_rotate_size cap set in containers/*/cloud.yml inert. set -euo pipefail TAG=nextcloud-cron INSTANCE={{ cron_name }} log() { logger -t "$TAG" -p daemon.info -- "instance=$INSTANCE $*"; } fail() { logger -t "$TAG" -p daemon.err -- "instance=$INSTANCE status=failed $*" echo "$TAG: FAILED: $*" >&2; exit 1; } # The Nextcloud containers are ROOTLESS podman owned by "{{ podman_user }}", # but this script runs as root under systemd. Same sudo/cd/XDG_RUNTIME_DIR # preamble as cloud-backup.sh -- see CLAUDE.md for why `cd;` is required. pexec() { sudo -H -u {{ podman_user }} bash -c \ 'cd; d=/run/user/$(id -u); [ -d "$d" ] && export XDG_RUNTIME_DIR="$d" exec podman "$@"' _ "$@" } # A container that is down (deploy, image bump, host reboot) is not a failure # worth flagging -- the next tick picks it up five minutes later. if ! pexec container exists {{ cron_container }} 2>/dev/null; then log "status=skipped reason=container-absent" exit 0 fi # occ and cron.php both refuse to do anything useful mid-upgrade. Skipping # keeps a deploy window from parading as a run of failed units. if pexec exec -u www-data {{ cron_container }} php occ status 2>/dev/null \ | grep -q 'maintenance: true'; then log "status=skipped reason=maintenance" exit 0 fi set +e pexec exec -u www-data {{ cron_container }} php -f /var/www/html/cron.php rc=$? set -e [ "$rc" -eq 0 ] || fail "cron.php exited $rc" log "status=ok"