From 5b995c205b8d5832cd39af3b64037ac98ebdec48 Mon Sep 17 00:00:00 2001 From: casjay Date: Mon, 3 Aug 2026 10:47:06 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20database=20dir=20excluded?= =?UTF-8?q?=20from=20permission=20fixup,=20causing=20restart=20loop=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: the `git` service user's UID is assigned dynamically (random, non-persistent across container recreations), and __fix_permissions re-chowns APPLICATION_DIRS on every startup to whatever UID `git` currently has. However DATABASE_DIR / DATABASE_BASE_DIR (e.g. /data/db/sqlite for the sqlite backend) live under /data/db, outside APPLICATION_DIRS ($ETC_DIR $CONF_DIR $DATA_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR, where DATA_DIR is /data/opengist, not /data). So whenever the on-disk DB ownership didn't already match the current `git` UID, it was never corrected, and opengist failed every start with "attempt to write a readonly database (8)", causing the container to exit and get restarted indefinitely. Reproduced against a live instance (git.casjay.work, casjaysdevdocker/opengist:latest): confirmed via container logs and `id git` vs `ls -la /data/db/sqlite` that the sqlite file's owning UID did not match the current `git` UID, and manually chowning it fixed that boot but the mismatch could recur on any future UID reassignment. Reproduced locally by pre-seeding a volume with the DB owned by an arbitrary UID (9999) and confirming, pre-fix, __fix_permissions never touched it; post-fix, the container's first boot re-chowns it to the newly assigned `git` UID and opengist starts cleanly. - rootfs/usr/local/etc/docker/init.d/00-opengist.sh: after the database-type case block resolves DATABASE_DIR/DATABASE_BASE_DIR, append both to ADD_APPLICATION_DIRS so __fix_permissions picks them up on every startup, regardless of database backend --- rootfs/usr/local/etc/docker/init.d/00-opengist.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rootfs/usr/local/etc/docker/init.d/00-opengist.sh b/rootfs/usr/local/etc/docker/init.d/00-opengist.sh index f13afb7..b7b2629 100755 --- a/rootfs/usr/local/etc/docker/init.d/00-opengist.sh +++ b/rootfs/usr/local/etc/docker/init.d/00-opengist.sh @@ -830,6 +830,18 @@ if [ -n "$DATABASE_ADMIN_WWW_ROOT" ]; then fi fi # - - - - - - - - - - - - - - - - - - - - - - - - - +# Ensure the database directory ownership gets fixed by __fix_permissions; +# it lives under DATABASE_BASE_DIR, outside APPLICATION_DIRS, so a UID +# mismatch here (e.g. after the service user gets a new random UID) is +# never corrected, leaving a stale-owned sqlite file that opengist can't +# write to and causing a permanent restart loop. +if [ -n "$DATABASE_DIR" ]; then + ADD_APPLICATION_DIRS="$ADD_APPLICATION_DIRS $DATABASE_DIR" +fi +if [ -n "$DATABASE_BASE_DIR" ]; then + ADD_APPLICATION_DIRS="$ADD_APPLICATION_DIRS $DATABASE_BASE_DIR" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - # Allow variables via imports - Overwrite existing if [ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"