Compose stack (MariaDB + Koha built from the Koha project's Debian packages), headless bootstrap replacing the web installer, seeded item types and LoC Z39.50 server, and an install.sh that installs Docker, generates passwords and waits for the site. End-to-end testing in progress. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013wi3ZSot4XbUViwRFgLpRf
81 lines
3.8 KiB
Bash
Executable File
81 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Container entrypoint: (re)creates the Koha instance config from environment
|
|
# variables on every start, installs the database on the first start, then runs
|
|
# Apache in the foreground. All durable state lives in MariaDB and /var/lib/koha.
|
|
set -euo pipefail
|
|
|
|
INST="${KOHA_INSTANCE:-library}"
|
|
DB_HOST="${KOHA_DB_HOST:-db}"
|
|
DB_NAME="${KOHA_DB_NAME:-koha_library}"
|
|
DB_USER="${KOHA_DB_USER:-koha_library}"
|
|
: "${KOHA_DB_PASS:?KOHA_DB_PASS is required}"
|
|
: "${KOHA_ADMIN_PASS:?KOHA_ADMIN_PASS is required}"
|
|
STAFF_PORT=8081
|
|
export TZ="${TZ:-UTC}"
|
|
|
|
log() { echo "[koha-init] $*"; }
|
|
|
|
# --- 1. memcached (Koha caches sysprefs and sessions in it) -----------------
|
|
memcached -u memcache -m 64 -d
|
|
cron
|
|
|
|
# --- 2. wait for MariaDB ----------------------------------------------------
|
|
log "waiting for database at $DB_HOST..."
|
|
for i in $(seq 1 120); do
|
|
mariadb -h "$DB_HOST" -u "$DB_USER" -p"$KOHA_DB_PASS" "$DB_NAME" -e 'select 1' >/dev/null 2>&1 && break
|
|
[ "$i" = 120 ] && { log "database never became ready"; exit 1; }
|
|
sleep 2
|
|
done
|
|
|
|
# --- 3. instance config (regenerated each time a container is created) ------
|
|
if [ ! -d "/etc/koha/sites/$INST" ]; then
|
|
log "creating Koha instance '$INST'..."
|
|
sed -i \
|
|
-e 's|^DOMAIN=.*|DOMAIN=""|' \
|
|
-e 's|^INTRASUFFIX=.*|INTRASUFFIX=""|' \
|
|
-e "s|^INTRAPORT=.*|INTRAPORT=\"$STAFF_PORT\"|" \
|
|
/etc/koha/koha-sites.conf
|
|
echo "$INST:$DB_USER:$KOHA_DB_PASS:$DB_NAME:$DB_HOST" > /etc/koha/passwd
|
|
koha-create --use-db --dbhost "$DB_HOST" --timezone "$TZ" \
|
|
--memcached-servers 127.0.0.1:11211 "$INST" 2>&1 | grep -v AH00558 || true
|
|
|
|
# No RabbitMQ in this stack: workers fall back to polling the database.
|
|
CONF="/etc/koha/sites/$INST/koha-conf.xml"
|
|
perl -0pi -e 's|\s*<message_broker>.*?</message_broker>||s' "$CONF"
|
|
|
|
# Serve both interfaces through Plack (much faster than plain CGI).
|
|
SITE="/etc/apache2/sites-available/$INST.conf"
|
|
sed -i \
|
|
-e 's|^\(\s*\)Include /etc/koha/apache-shared-opac.conf|\1Include /etc/koha/apache-shared-opac-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-intranet-plack.conf||' "$SITE"
|
|
koha-plack --enable "$INST" >/dev/null
|
|
grep -q '^ServerName' /etc/apache2/apache2.conf || echo 'ServerName localhost' >> /etc/apache2/apache2.conf
|
|
fi
|
|
chown -R "$INST-koha:$INST-koha" "/var/lib/koha/$INST" "/var/log/koha/$INST" 2>/dev/null || true
|
|
|
|
# --- 4. install or upgrade the database -------------------------------------
|
|
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"
|
|
FIRST_RUN=1
|
|
else
|
|
log "existing database found - applying any pending upgrades..."
|
|
koha-upgrade-schema "$INST" || log "WARNING: koha-upgrade-schema reported a problem (see output above)"
|
|
FIRST_RUN=0
|
|
fi
|
|
|
|
# --- 5. search index (Zebra) ------------------------------------------------
|
|
koha-plack --restart "$INST" >/dev/null 2>&1 || koha-plack --start "$INST" >/dev/null 2>&1 || true
|
|
koha-worker --restart "$INST" >/dev/null 2>&1 || true
|
|
if [ "$FIRST_RUN" = 1 ] || [ ! -e "/var/lib/koha/$INST/biblios/register" ]; then
|
|
log "building search index..."
|
|
koha-rebuild-zebra -f -b -a -v "$INST" >/dev/null 2>&1 || koha-rebuild-zebra -f -v "$INST" || true
|
|
fi
|
|
|
|
log "ready - library catalogue on :80, staff interface on :$STAFF_PORT"
|
|
exec apache2ctl -D FOREGROUND
|