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 <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
d8b3d46634
commit
bf8529fbd4
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,110 @@
|
|||
#!/bin/sh
|
||||
# koha-generate-env -- Generate EnvironmentFile for systemd units
|
||||
# Usage: koha-generate-env <service> <instance>
|
||||
#
|
||||
# Reads koha-conf.xml and writes /run/koha/<instance>/<service>.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 <service> <instance>" >&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" <<EOF
|
||||
PLACK_WORKERS=${WORKERS:-2}
|
||||
PLACK_MAX_REQUESTS=${MAX_REQUESTS:-50}
|
||||
PLACK_ENVIRONMENT=${ENVIRONMENT}
|
||||
PLACK_PSGIFILE=${PSGIFILE}
|
||||
EOF
|
||||
;;
|
||||
|
||||
zebra)
|
||||
LOGLEVELS=$(xml_val zebra_loglevels)
|
||||
MAX_RECORD_SIZE=$(xml_val zebra_max_record_size)
|
||||
|
||||
cat > "$ENVFILE" <<EOF
|
||||
ZEBRA_LOGLEVELS=${LOGLEVELS:-none,fatal,warn}
|
||||
ZEBRA_MAX_RECORD_SIZE=${MAX_RECORD_SIZE:-1024}
|
||||
EOF
|
||||
;;
|
||||
|
||||
es-indexer)
|
||||
BATCH_SIZE=$(xml_val es_indexer_batch_size)
|
||||
|
||||
cat > "$ENVFILE" <<EOF
|
||||
ES_BATCH_SIZE=${BATCH_SIZE:-10}
|
||||
EOF
|
||||
;;
|
||||
|
||||
indexer)
|
||||
# Read from /etc/default/koha-common if available
|
||||
INDEXER_TIMEOUT=5
|
||||
if [ -f /etc/default/koha-common ]; then
|
||||
. /etc/default/koha-common
|
||||
fi
|
||||
|
||||
cat > "$ENVFILE" <<EOF
|
||||
INDEXER_TIMEOUT=${INDEXER_TIMEOUT:-5}
|
||||
EOF
|
||||
;;
|
||||
|
||||
z3950)
|
||||
# Determine config dir: per-instance or global
|
||||
CONFIGDIR="/etc/koha/z3950"
|
||||
if [ -d "/etc/koha/sites/${INSTANCE}/z3950" ]; then
|
||||
CONFIGDIR="/etc/koha/sites/${INSTANCE}/z3950"
|
||||
fi
|
||||
|
||||
# Read additional options from config
|
||||
Z3950_OPTS=""
|
||||
if [ -f "${CONFIGDIR}/config.xml" ]; then
|
||||
Z3950_OPTS=$(xmlstarlet sel -t -v "//z3950_responder_options" "${CONFIGDIR}/config.xml" 2>/dev/null || true)
|
||||
fi
|
||||
|
||||
cat > "$ENVFILE" <<EOF
|
||||
Z3950_CONFIGDIR=${CONFIGDIR}
|
||||
Z3950_ADDITIONAL_OPTS=${Z3950_OPTS}
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
||||
chmod 640 "$ENVFILE"
|
||||
chown root:"${INSTANCE}-koha" "$ENVFILE"
|
||||
|
|
@ -12,7 +12,9 @@ WorkingDirectory=/var/lib/koha/%i
|
|||
Environment=KOHA_CONF=/etc/koha/sites/%i/koha-conf.xml
|
||||
Environment=KOHA_HOME=/usr/share/koha
|
||||
Environment=PERL5LIB=/usr/share/koha/lib
|
||||
ExecStart=/usr/share/koha/bin/workers/es_indexer_daemon.pl
|
||||
ExecStartPre=+/usr/sbin/koha-generate-env es-indexer %i
|
||||
EnvironmentFile=-/run/koha/%i/es-indexer.env
|
||||
ExecStart=/usr/share/koha/bin/workers/es_indexer_daemon.pl --batch_size ${ES_BATCH_SIZE}
|
||||
Restart=on-failure
|
||||
RestartSec=30s
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ WorkingDirectory=/var/lib/koha/%i
|
|||
Environment=KOHA_CONF=/etc/koha/sites/%i/koha-conf.xml
|
||||
Environment=KOHA_HOME=/usr/share/koha
|
||||
Environment=PERL5LIB=/usr/share/koha/lib
|
||||
ExecStart=/usr/share/koha/bin/migration_tools/rebuild_zebra.pl -daemon -sleep 5
|
||||
ExecStartPre=+/usr/sbin/koha-generate-env indexer %i
|
||||
EnvironmentFile=-/run/koha/%i/indexer.env
|
||||
ExecStart=/usr/share/koha/bin/migration_tools/rebuild_zebra.pl -daemon -sleep ${INDEXER_TIMEOUT}
|
||||
Restart=on-failure
|
||||
RestartSec=30s
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,20 @@ Environment=KOHA_CONF=/etc/koha/sites/%i/koha-conf.xml
|
|||
Environment=KOHA_HOME=/usr/share/koha
|
||||
Environment=PERL5LIB=/usr/share/koha/lib
|
||||
PIDFile=/var/run/koha/%i/plack.pid
|
||||
ExecStart=/usr/bin/plackup -s Starman --daemonize --pid /var/run/koha/%i/plack.pid --listen /var/run/koha/%i/plack.sock /etc/koha/plack.psgi
|
||||
ExecStartPre=+/usr/sbin/koha-generate-env plack %i
|
||||
EnvironmentFile=-/run/koha/%i/plack.env
|
||||
ExecStart=/usr/bin/starman \
|
||||
-M FindBin \
|
||||
--max-requests ${PLACK_MAX_REQUESTS} \
|
||||
--workers ${PLACK_WORKERS} \
|
||||
--user %i-koha --group %i-koha \
|
||||
--pid /var/run/koha/%i/plack.pid \
|
||||
--daemonize \
|
||||
--access-log /var/log/koha/%i/plack.log \
|
||||
--error-log /var/log/koha/%i/plack-error.log \
|
||||
-E ${PLACK_ENVIRONMENT} \
|
||||
--listen /var/run/koha/%i/plack.sock \
|
||||
${PLACK_PSGIFILE}
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ Description=Koha Z39.50/SRU server for %i
|
|||
PartOf=koha@%i.target
|
||||
Requires=koha-create-dirs@%i.service
|
||||
After=koha@%i.target
|
||||
ConditionPathExists=/etc/koha/sites/%i/z3950/config.xml
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
|
|
@ -14,7 +13,16 @@ Environment=KOHA_CONF=/etc/koha/sites/%i/koha-conf.xml
|
|||
Environment=KOHA_HOME=/usr/share/koha
|
||||
Environment=PERL5LIB=/usr/share/koha/lib
|
||||
PIDFile=/var/run/koha/%i/z3950-responder.pid
|
||||
ExecStart=/usr/share/koha/bin/z3950_responder.pl -c /etc/koha/sites/%i/z3950 -u %i-koha -p /var/run/koha/%i/z3950-responder.pid -D -d %i-koha-z3950 -l /var/log/koha/%i/z3950.log
|
||||
ExecStartPre=+/usr/sbin/koha-generate-env z3950 %i
|
||||
EnvironmentFile=-/run/koha/%i/z3950.env
|
||||
ExecStart=/usr/share/koha/bin/z3950_responder.pl \
|
||||
${Z3950_ADDITIONAL_OPTS} \
|
||||
-c ${Z3950_CONFIGDIR} \
|
||||
-u %i-koha \
|
||||
-p /var/run/koha/%i/z3950-responder.pid \
|
||||
-D \
|
||||
-d %i-koha-z3950 \
|
||||
-l /var/log/koha/%i/z3950.log
|
||||
Restart=on-failure
|
||||
RestartSec=30s
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,15 @@ WorkingDirectory=/var/lib/koha/%i
|
|||
Environment=KOHA_CONF=/etc/koha/sites/%i/koha-conf.xml
|
||||
Environment=KOHA_HOME=/usr/share/koha
|
||||
PIDFile=/var/run/koha/%i/zebra.pid
|
||||
ExecStart=/usr/bin/zebrasrv -f /etc/koha/sites/%i/koha-conf.xml -p /var/run/koha/%i/zebra.pid -D
|
||||
ExecStartPre=+/usr/sbin/koha-generate-env zebra %i
|
||||
EnvironmentFile=-/run/koha/%i/zebra.env
|
||||
ExecStart=/usr/bin/zebrasrv \
|
||||
-v ${ZEBRA_LOGLEVELS} \
|
||||
-k ${ZEBRA_MAX_RECORD_SIZE} \
|
||||
-f /etc/koha/sites/%i/koha-conf.xml \
|
||||
-m '%%FT%%T' \
|
||||
-p /var/run/koha/%i/zebra.pid \
|
||||
-D
|
||||
Restart=on-failure
|
||||
RestartSec=30s
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue