🐛 Fix database dir excluded from permission fixup, causing restart loop 🐛

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
This commit is contained in:
2026-08-03 10:47:06 -04:00
parent b016f1db1d
commit 5b995c205b
@@ -830,6 +830,18 @@ if [ -n "$DATABASE_ADMIN_WWW_ROOT" ]; then
fi fi
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 # Allow variables via imports - Overwrite existing
if [ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then if [ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then
. "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"