Koha-clms/debian/koha-systemd.postinst

74 lines
3.4 KiB
Bash

#!/bin/sh
set -e
case "$1" in
configure)
# Reload systemd daemon
systemctl daemon-reload || true
# Stop and disable the legacy SysV koha-common.service if present.
# This service is auto-generated by systemd-sysv-generator from
# /etc/init.d/koha-common and would run in parallel with the native
# systemd units, causing double-starts.
if systemctl is-active --quiet koha-common.service 2>/dev/null; then
systemctl stop koha-common.service || true
fi
if systemctl is-enabled --quiet koha-common.service 2>/dev/null; then
systemctl disable koha-common.service || true
fi
# Remove the orphaned SysV init script if it was left behind by
# the old koha-common package (pre-split) and koha-sysv is not installed.
if [ -f /etc/init.d/koha-common ] && ! dpkg -s koha-sysv >/dev/null 2>&1; then
rm -f /etc/init.d/koha-common
systemctl daemon-reload || true
fi
# On first install (no previous version), enable units for all existing instances
# This handles migration from SysV init to systemd
if [ -z "$2" ]; then
for instance in $(koha-list --enabled 2>/dev/null); do
# Core services: always enable
systemctl enable koha-zebra@${instance}.service 2>/dev/null || true
systemctl enable koha-plack@${instance}.service 2>/dev/null || true
systemctl enable koha-worker@${instance}.service 2>/dev/null || true
systemctl enable koha-worker-long_tasks@${instance}.service 2>/dev/null || true
systemctl enable koha-create-dirs@${instance}.service 2>/dev/null || true
systemctl enable koha@${instance}.target 2>/dev/null || true
# Conditional services
# SIP: read the SysV-era flag file DIRECTLY here, not via
# koha-list --sip / is_sip_enabled. The latter now consults
# systemctl is-enabled on systemd hosts (see follow-up 1/3),
# which would return "disabled" for every instance during this
# very first install -- the migration we are about to perform.
# The flag file is the only reliable signal for "did this
# instance have SIP enabled in the SysV-era state we are
# migrating from?".
if [ -e "/var/lib/koha/${instance}/sip.enabled" ]; then
systemctl enable koha-sip@${instance}.service 2>/dev/null || true
fi
if koha-list --enabled --z3950 2>/dev/null | grep -qx "$instance"; then
systemctl enable koha-z3950@${instance}.service 2>/dev/null || true
fi
if koha-list --enabled --elasticsearch 2>/dev/null | grep -qx "$instance"; then
systemctl enable koha-es-indexer@${instance}.service 2>/dev/null || true
else
systemctl enable koha-indexer@${instance}.service 2>/dev/null || true
fi
done
systemctl enable koha.target 2>/dev/null || true
fi
# On upgrade, restart running Koha services so they pick up new code/unit files
if [ -n "$2" ]; then
deb-systemd-invoke try-restart \
'koha-*@*.service' \
>/dev/null || true
fi
;;
esac
#DEBHELPER#
exit 0