library: run bootstrap via runuser, keep mpm_itk, add SETUID/SETGID caps

- koha-shell -c wraps the command in single quotes, which broke the env
  assignments; use runuser + env instead and verify tables were created
- koha-create requires mpm_itk, so keep it and grant the caps it needs
- stop any Apache started by koha-create before running it in foreground

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013wi3ZSot4XbUViwRFgLpRf
This commit is contained in:
Claude
2026-11-06 06:29:27 +00:00
parent 7244cfd918
commit a15478b382
2 changed files with 18 additions and 1 deletions
+4
View File
@@ -37,6 +37,10 @@ services:
KOHA_ADMIN_USER: ${ADMIN_USER:-admin}
KOHA_ADMIN_PASS: ${ADMIN_PASSWORD}
KOHA_LIBRARY_NAME: ${LIBRARY_NAME:-My Library}
# Koha's Apache uses mpm_itk, which switches users per request.
cap_add:
- SETUID
- SETGID
ports:
- "${OPAC_PORT:-8080}:80"
- "${STAFF_PORT:-8081}:8081"
+14 -1
View File
@@ -68,7 +68,15 @@ TABLES=$(mariadb -N -h "$DB_HOST" -u "$DB_USER" -p"$KOHA_DB_PASS" "$DB_NAME" \
-e "select count(*) from information_schema.tables where table_schema='$DB_NAME'")
if [ "$TABLES" = "0" ]; then
log "first start: installing Koha (about a minute)..."
koha-shell -c "KOHA_ADMIN_USER='${KOHA_ADMIN_USER:-admin}' KOHA_ADMIN_PASS='$KOHA_ADMIN_PASS' KOHA_LIBRARY_NAME='${KOHA_LIBRARY_NAME:-My Library}' TZ='$TZ' perl /opt/koha-init/bootstrap.pl" "$INST"
# (not koha-shell -c: it wraps the command in single quotes of its own)
runuser -u "$INST-koha" -- env \
KOHA_CONF="/etc/koha/sites/$INST/koha-conf.xml" \
KOHA_ADMIN_USER="${KOHA_ADMIN_USER:-admin}" KOHA_ADMIN_PASS="$KOHA_ADMIN_PASS" \
KOHA_LIBRARY_NAME="${KOHA_LIBRARY_NAME:-My Library}" TZ="$TZ" \
perl /opt/koha-init/bootstrap.pl
TABLES=$(mariadb -N -h "$DB_HOST" -u "$DB_USER" -p"$KOHA_DB_PASS" "$DB_NAME" \
-e "select count(*) from information_schema.tables where table_schema='$DB_NAME'")
[ "$TABLES" -gt 0 ] || { log "ERROR: installation did not create the database"; exit 1; }
FIRST_RUN=1
else
log "existing database found - applying any pending upgrades..."
@@ -87,5 +95,10 @@ for svc in koha-zebra koha-indexer koha-worker koha-plack; do
|| log "WARNING: could not start $svc"
done
# koha-create / koha-plack may have started Apache already; run it in the foreground instead.
apache2ctl -k stop >/dev/null 2>&1 || true
for i in 1 2 3 4 5; do pgrep -x apache2 >/dev/null || break; sleep 1; done
rm -f /var/run/apache2/apache2.pid
log "ready - library catalogue on :80, staff interface on :$STAFF_PORT"
exec apache2ctl -D FOREGROUND