LibrePortal/containers/nextcloud/scripts/nextcloud_update_specifics.sh
librelad af23488df1 tidy: docs + Nextcloud APCu + container-side file-capture rollout
Three closeouts in one pass:

1. DEVELOPMENT.md — consolidated hook-conventions table covering all 8 per-app
   hook types (tools / update-specifics / compose-tags / webui-refresh / the two
   traefik markers / the two network-provider hooks). One place to look instead
   of inferring from the codebase.

2. Nextcloud APCu wired alongside Redis: appUpdateSpecifics_nextcloud now sets
   memcache.local=\OC\Memcache\APCu too (was deferred from the fpm switch). APCu
   = cheap in-process cache; the fpm-alpine image ships the extension. CLI mode
   may emit a harmless "no memory cache" notice on `occ` runs — Nextcloud is
   graceful, the FPM worker still uses APCu fine.

3. Container-side file-capture rollout to 3 confident cases:
   - bookstack: lscr.io/linuxserver/bookstack with PUID=1000 → /config (1000:1000)
   - gitea:     gitea/gitea with USER_UID=1000     → /data    (1000:1000)
   - owncloud:  owncloud/server (Apache/PHP)        → /mnt/data (33:33, www-data)
   Snapshots are now complete for these (the dir's excluded from the raw restic
   pass and captured live through the container as a tar → libreportal-owned
   staging, same proven pattern as Nextcloud). Less-evidenced candidates left
   for live verification: linkding, mastodon, jellyfin, trilium, focalboard,
   invidious, vaultwarden, headscale-service — each needs its in-container uid
   confirmed before labeling (wrong uid won't break backup, but restore would
   chown to the wrong owner).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-26 14:43:28 +01:00

45 lines
2.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Post-install/update specifics for Nextcloud — dispatched by appUpdateSpecifics.
#
# Nextcloud's official image runs `occ maintenance:install` on first boot from the
# NEXTCLOUD_ADMIN_USER + MYSQL_* env vars (so no web wizard). After that, wire
# Redis as the distributed cache + file-locking backend — this is the actual
# performance win for sync-heavy workloads. The redis container is on the same
# docker network as nextcloud-service, so the hostname `nextcloud-redis` resolves.
# Idempotent: `occ config:system:set` with the same value is a no-op.
appUpdateSpecifics_nextcloud() {
# Wait for Nextcloud's first-boot init to complete (config.php exists +
# occ reports installed). 60 × 2s = 2 minute timeout.
local i=0
while (( i++ < 60 )); do
if runFileOp docker exec -u www-data nextcloud-service test -f /var/www/html/config/config.php 2>/dev/null \
&& runFileOp docker exec -u www-data nextcloud-service php occ status 2>/dev/null | grep -q 'installed: true'; then
break
fi
sleep 2
done
if (( i >= 60 )); then
isNotice "Nextcloud not yet initialized; skipping Redis wiring (re-run by reinstalling once it's up)"
return 0
fi
isNotice "Wiring Redis caching + APCu into Nextcloud..."
local rc=0
# APCu = in-process local cache (cheap, fast). The fpm image ships with the
# apcu PHP extension; under CLI mode it isn't enabled by default which makes
# `occ` emit a harmless "memory cache not available" notice — Nextcloud's
# graceful, the FPM worker still uses APCu fine.
runFileOp docker exec -u www-data nextcloud-service php occ config:system:set memcache.local --value '\OC\Memcache\APCu' >/dev/null 2>&1 || rc=1
runFileOp docker exec -u www-data nextcloud-service php occ config:system:set memcache.distributed --value '\OC\Memcache\Redis' >/dev/null 2>&1 || rc=1
runFileOp docker exec -u www-data nextcloud-service php occ config:system:set memcache.locking --value '\OC\Memcache\Redis' >/dev/null 2>&1 || rc=1
runFileOp docker exec -u www-data nextcloud-service php occ config:system:set redis host --value nextcloud-redis >/dev/null 2>&1 || rc=1
runFileOp docker exec -u www-data nextcloud-service php occ config:system:set redis port --value 6379 --type=integer >/dev/null 2>&1 || rc=1
runFileOp docker exec -u www-data nextcloud-service php occ config:system:set filelocking.enabled --value true --type=boolean >/dev/null 2>&1 || rc=1
if [[ $rc -eq 0 ]]; then
isSuccessful "Nextcloud → APCu (local) + Redis (distributed + file-locking) wired."
else
isNotice "Cache wiring had errors (non-fatal; Nextcloud still functions without it)"
fi
}