library: fix entrypoint (Apache user, Listen 8081, start daemons each boot) and crash detection

- Run Apache as the instance user instead of mpm_itk AssignUserID
- Add Listen for the staff port; start zebra/indexer/worker/plack explicitly
- Tolerate koha-plack --enable returning non-zero under set -e
- install.sh: only fail on a crash loop, not a single restart

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:20:45 +00:00
parent 5b79608695
commit 7244cfd918
2 changed files with 20 additions and 6 deletions
+4 -1
View File
@@ -116,7 +116,10 @@ dc up -d
c_info "First start installs the database - waiting for the staff interface..." c_info "First start installs the database - waiting for the staff interface..."
for i in $(seq 1 120); do for i in $(seq 1 120); do
if curl -fsS -o /dev/null "http://127.0.0.1:$STAFF_PORT/" 2>/dev/null; then READY=1; break; fi if curl -fsS -o /dev/null "http://127.0.0.1:$STAFF_PORT/" 2>/dev/null; then READY=1; break; fi
if ! docker ps --format '{{.Names}}' | grep -qx library-koha; then c_err "library-koha stopped - see: docker logs library-koha"; exit 1; fi # One restart is tolerated (Docker's restart policy); a crash loop is not.
if [ "$(docker inspect -f '{{.RestartCount}}' library-koha 2>/dev/null || echo 99)" -ge 3 ]; then
c_err "library-koha keeps crashing - see: docker logs library-koha"; exit 1
fi
sleep 5 sleep 5
done done
[ "${READY:-0}" = 1 ] || { c_err "Timed out - see: docker logs -f library-koha"; exit 1; } [ "${READY:-0}" = 1 ] || { c_err "Timed out - see: docker logs -f library-koha"; exit 1; }
+16 -5
View File
@@ -50,7 +50,15 @@ if [ ! -d "/etc/koha/sites/$INST" ]; then
-e 's|^\(\s*\)Include /etc/koha/apache-shared-intranet.conf|\1Include /etc/koha/apache-shared-intranet-plack.conf|' \ -e 's|^\(\s*\)Include /etc/koha/apache-shared-intranet.conf|\1Include /etc/koha/apache-shared-intranet-plack.conf|' \
-e 's|^#\s*Include /etc/koha/apache-shared-opac-plack.conf||' \ -e 's|^#\s*Include /etc/koha/apache-shared-opac-plack.conf||' \
-e 's|^#\s*Include /etc/koha/apache-shared-intranet-plack.conf||' "$SITE" -e 's|^#\s*Include /etc/koha/apache-shared-intranet-plack.conf||' "$SITE"
koha-plack --enable "$INST" >/dev/null koha-plack --enable "$INST" >/dev/null 2>&1 || true # koha-create may already have enabled it
# Run Apache itself as the instance user instead of mpm_itk's per-vhost
# uid switching (which needs extra capabilities and is pointless here:
# Plack does the real work as that user already).
sed -i '/AssignUserID/d' "$SITE"
sed -i -e "s/^export APACHE_RUN_USER=.*/export APACHE_RUN_USER=$INST-koha/" \
-e "s/^export APACHE_RUN_GROUP=.*/export APACHE_RUN_GROUP=$INST-koha/" /etc/apache2/envvars
grep -q "^Listen $STAFF_PORT\b" /etc/apache2/ports.conf || echo "Listen $STAFF_PORT" >> /etc/apache2/ports.conf
grep -q '^ServerName' /etc/apache2/apache2.conf || echo 'ServerName localhost' >> /etc/apache2/apache2.conf grep -q '^ServerName' /etc/apache2/apache2.conf || echo 'ServerName localhost' >> /etc/apache2/apache2.conf
fi fi
chown -R "$INST-koha:$INST-koha" "/var/lib/koha/$INST" "/var/log/koha/$INST" 2>/dev/null || true chown -R "$INST-koha:$INST-koha" "/var/lib/koha/$INST" "/var/log/koha/$INST" 2>/dev/null || true
@@ -68,13 +76,16 @@ else
FIRST_RUN=0 FIRST_RUN=0
fi fi
# --- 5. search index (Zebra) ------------------------------------------------ # --- 5. background services (their `daemon` processes die with the container,
koha-plack --restart "$INST" >/dev/null 2>&1 || koha-plack --start "$INST" >/dev/null 2>&1 || true # so they are started explicitly on every start) ------------------------
koha-worker --restart "$INST" >/dev/null 2>&1 || true
if [ "$FIRST_RUN" = 1 ] || [ ! -e "/var/lib/koha/$INST/biblios/register" ]; then if [ "$FIRST_RUN" = 1 ] || [ ! -e "/var/lib/koha/$INST/biblios/register" ]; then
log "building search index..." log "building search index..."
koha-rebuild-zebra -f -b -a -v "$INST" >/dev/null 2>&1 || koha-rebuild-zebra -f -v "$INST" || true koha-rebuild-zebra -f -v "$INST" >/dev/null 2>&1 || true
fi fi
for svc in koha-zebra koha-indexer koha-worker koha-plack; do
"$svc" --restart "$INST" >/dev/null 2>&1 || "$svc" --start "$INST" >/dev/null 2>&1 \
|| log "WARNING: could not start $svc"
done
log "ready - library catalogue on :80, staff interface on :$STAFF_PORT" log "ready - library catalogue on :80, staff interface on :$STAFF_PORT"
exec apache2ctl -D FOREGROUND exec apache2ctl -D FOREGROUND