From bf8529fbd4fb7bd099943130657f0f52e6bdce6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Tue, 28 Apr 2026 21:37:44 -0300 Subject: [PATCH] Bug 40901: (follow-up) Read service config from koha-conf.xml in systemd units The systemd units were missing most of the parameters that the SysV init functions read from koha-conf.xml. This caused wrong worker counts, missing log files, ignored batch sizes, and other config being silently dropped. This patch adds koha-generate-env, a helper script that reads koha-conf.xml and writes an EnvironmentFile for each service. Each unit runs it as ExecStartPre and then uses the variables. Changes per unit: - koha-plack@: workers, max-requests, access/error logs, environment (development/deployment), per-instance psgi, -M FindBin - koha-zebra@: loglevels, max_record_size, timestamp format - koha-es-indexer@: batch_size - koha-indexer@: INDEXER_TIMEOUT from /etc/default/koha-common - koha-z3950@: config dir fallback to global, additional options Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Pedro Amorim --- debian/koha-systemd.install | 1 + debian/scripts/koha-generate-env | 110 ++++++++++++++++++++++++ debian/systemd/koha-es-indexer@.service | 4 +- debian/systemd/koha-indexer@.service | 4 +- debian/systemd/koha-plack@.service | 15 +++- debian/systemd/koha-z3950@.service | 12 ++- debian/systemd/koha-zebra@.service | 10 ++- 7 files changed, 150 insertions(+), 6 deletions(-) create mode 100755 debian/scripts/koha-generate-env diff --git a/debian/koha-systemd.install b/debian/koha-systemd.install index 06952f8299..2ca74958b5 100644 --- a/debian/koha-systemd.install +++ b/debian/koha-systemd.install @@ -1,3 +1,4 @@ debian/systemd/*.service usr/lib/systemd/system debian/systemd/*.target usr/lib/systemd/system debian/systemd/koha-systemd-ctl usr/sbin +debian/scripts/koha-generate-env usr/sbin diff --git a/debian/scripts/koha-generate-env b/debian/scripts/koha-generate-env new file mode 100755 index 0000000000..01e75f388e --- /dev/null +++ b/debian/scripts/koha-generate-env @@ -0,0 +1,110 @@ +#!/bin/sh +# koha-generate-env -- Generate EnvironmentFile for systemd units +# Usage: koha-generate-env +# +# Reads koha-conf.xml and writes /run/koha//.env +# with the parameters that the corresponding systemd unit needs. + +set -e + +SERVICE="$1" +INSTANCE="$2" + +if [ -z "$SERVICE" ] || [ -z "$INSTANCE" ]; then + echo "Usage: koha-generate-env " >&2 + exit 1 +fi + +CONF="/etc/koha/sites/${INSTANCE}/koha-conf.xml" +ENVDIR="/run/koha/${INSTANCE}" +ENVFILE="${ENVDIR}/${SERVICE}.env" + +if [ ! -f "$CONF" ]; then + echo "Error: $CONF not found" >&2 + exit 1 +fi + +# Safe xmlstarlet wrapper: returns empty string if key not found +xml_val() { + xmlstarlet sel -t -v "yazgfs/config/$1" "$CONF" 2>/dev/null || true +} + +mkdir -p "$ENVDIR" + +case "$SERVICE" in + plack) + WORKERS=$(xml_val plack_workers) + MAX_REQUESTS=$(xml_val plack_max_requests) + DEBUG_MODE=$(xml_val debug_mode) + + PSGIFILE="/etc/koha/plack.psgi" + if [ -f "/etc/koha/sites/${INSTANCE}/plack.psgi" ]; then + PSGIFILE="/etc/koha/sites/${INSTANCE}/plack.psgi" + fi + + if [ "$DEBUG_MODE" = "1" ] || [ "$DEBUG_MODE" = "true" ]; then + ENVIRONMENT="development" + else + ENVIRONMENT="deployment" + fi + + cat > "$ENVFILE" < "$ENVFILE" < "$ENVFILE" < "$ENVFILE" </dev/null || true) + fi + + cat > "$ENVFILE" <