diff --git a/debian/scripts/koha-es-indexer b/debian/scripts/koha-es-indexer index 6a30b44b0a..4407ec4fa7 100755 --- a/debian/scripts/koha-es-indexer +++ b/debian/scripts/koha-es-indexer @@ -59,96 +59,40 @@ EOF start_es_indexer() { local name=$1 - - if ! is_es_indexer_running $name; then - - export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - - DAEMONOPTS="--name=$name-koha-es-indexer \ - --errlog=/var/log/koha/$name/es-indexer-error.log \ - --output=/var/log/koha/$name/es-indexer-output.log \ - --pidfiles=/var/run/koha/$name/ \ - --verbose=1 --respawn --delay=30 \ - --user=$name-koha.$name-koha" - - log_daemon_msg "Starting Koha ES indexing daemon for $name" - - if daemon $DAEMONOPTS -- $worker_DAEMON --batch_size ${batch_size}; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl start es-indexer "$name" else - log_daemon_msg "Error: ES indexing daemon already running for $name" - log_end_msg 1 + _sysv_start_es_indexer "$name" fi } stop_es_indexer() { local name=$1 - - if is_es_indexer_running $name; then - export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - - DAEMONOPTS="--name=$name-koha-es-indexer \ - --errlog=/var/log/koha/$name/es-indexer-error.log \ - --output=/var/log/koha/$name/es-indexer-output.log \ - --pidfiles=/var/run/koha/$name/ \ - --verbose=1 --respawn --delay=30 \ - --user=$name-koha.$name-koha" - - log_daemon_msg "Stopping Koha ES indexing daemon for $name" - - if daemon $DAEMONOPTS --stop -- $worker_DAEMON; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl stop es-indexer "$name" else - log_daemon_msg "Error: ES indexing daemon not running for $name" - log_end_msg 1 + _sysv_stop_es_indexer "$name" fi } restart_es_indexer() { local name=$1 - local queue=$2 - - if is_es_indexer_running $name; then - export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - - DAEMONOPTS="--name=$name-koha-es-indexer \ - --errlog=/var/log/koha/$name/es-indexer-error.log \ - --output=/var/log/koha/$name/es-indexer-output.log \ - --pidfiles=/var/run/koha/$name/ \ - --verbose=1 --respawn --delay=30 \ - --user=$name-koha.$name-koha" - - log_daemon_msg "Restarting Koha ES indexing daemon for $name" - - if daemon $DAEMONOPTS --restart -- $worker_DAEMON --batch_size ${batch_size}; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl restart es-indexer "$name" else - log_warning_msg "ES indexing daemon not running for $name." - start_es_indexer $name + _sysv_restart_es_indexer "$name" fi } es_indexer_status() { local name=$1 - - if is_es_indexer_running $name; then - log_daemon_msg "ES indexing daemon running for ${name}" - log_end_msg 0 + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl status es-indexer "$name" else - log_daemon_msg "ES indexing daemon not running for ${name}" - log_end_msg 3 + _sysv_es_indexer_status "$name" fi } diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index ef138fce9b..73e2ca626e 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -157,60 +157,105 @@ is_sitemap_enabled() fi } +# --- Service management abstraction --- +# Systemd is the primary path. Legacy daemon/start-stop-daemon is the fallback. + +_KOHA_INIT_BACKEND="" + +koha_init_backend() +{ + if [ -z "$_KOHA_INIT_BACKEND" ]; then + if [ -d /run/systemd/system ] && \ + systemctl list-unit-files koha-plack@.service >/dev/null 2>&1; then + _KOHA_INIT_BACKEND="systemd" + else + _KOHA_INIT_BACKEND="sysv" + fi + fi + echo "$_KOHA_INIT_BACKEND" +} + +# Map service + queue to systemd unit name +_koha_systemd_unit() +{ + local service=$1 instance=$2 queue=$3 + + if [ "$service" = "worker" ] && [ -n "$queue" ] && [ "$queue" != "default" ]; then + echo "koha-worker-${queue}@${instance}.service" + else + echo "koha-${service}@${instance}.service" + fi +} + +# Unified service control: start|stop|restart|reload|status +koha_service_ctl() +{ + local action=$1 service=$2 instance=$3 queue=$4 + + local unit=$(_koha_systemd_unit "$service" "$instance" "$queue") + + case "$action" in + start|stop|restart) + systemctl "$action" "$unit" ;; + reload) + systemctl reload-or-restart "$unit" ;; + status) + systemctl status "$unit" ;; + esac +} + +# --- is_*_running: systemd-aware with legacy fallback --- + is_sip_running() { local instancename=$1 - - if daemon --name="$instancename-koha-sip" \ - --pidfiles="/var/run/koha/$instancename/" \ - --user="$instancename-koha.$instancename-koha" \ - --running ; then - return 0 - else - return 1 + if [ "$(koha_init_backend)" = "systemd" ]; then + systemctl is-active --quiet "$(_koha_systemd_unit sip $instancename)" + return fi + daemon --name="$instancename-koha-sip" \ + --pidfiles="/var/run/koha/$instancename/" \ + --user="$instancename-koha.$instancename-koha" \ + --running } is_zebra_running() { local instancename=$1 - - if daemon --name="$instancename-koha-zebra" \ - --pidfiles="/var/run/koha/$instancename/" \ - --user="$instancename-koha.$instancename-koha" \ - --running ; then - return 0 - else - return 1 + if [ "$(koha_init_backend)" = "systemd" ]; then + systemctl is-active --quiet "$(_koha_systemd_unit zebra $instancename)" + return fi + daemon --name="$instancename-koha-zebra" \ + --pidfiles="/var/run/koha/$instancename/" \ + --user="$instancename-koha.$instancename-koha" \ + --running } is_indexer_running() { local instancename=$1 - - if daemon --name="$instancename-koha-indexer" \ - --pidfiles="/var/run/koha/$instancename/" \ - --user="$instancename-koha.$instancename-koha" \ - --running ; then - return 0 - else - return 1 + if [ "$(koha_init_backend)" = "systemd" ]; then + systemctl is-active --quiet "$(_koha_systemd_unit indexer $instancename)" + return fi + daemon --name="$instancename-koha-indexer" \ + --pidfiles="/var/run/koha/$instancename/" \ + --user="$instancename-koha.$instancename-koha" \ + --running } is_es_indexer_running() { local instancename=$1 - - if daemon --name="$instancename-koha-es-indexer" \ - --pidfiles="/var/run/koha/$instancename/" \ - --user="$instancename-koha.$instancename-koha" \ - --running ; then - return 0 - else - return 1 + if [ "$(koha_init_backend)" = "systemd" ]; then + systemctl is-active --quiet "$(_koha_systemd_unit es-indexer $instancename)" + return fi + daemon --name="$instancename-koha-es-indexer" \ + --pidfiles="/var/run/koha/$instancename/" \ + --user="$instancename-koha.$instancename-koha" \ + --running } is_worker_running() @@ -218,16 +263,15 @@ is_worker_running() local instancename=$1 local queue=$2 - local name=`get_worker_name $instancename $queue` - - if daemon --name="$name" \ - --pidfiles="/var/run/koha/$instancename/" \ - --user="$instancename-koha.$instancename-koha" \ - --running ; then - return 0 - else - return 1 + if [ "$(koha_init_backend)" = "systemd" ]; then + systemctl is-active --quiet "$(_koha_systemd_unit worker $instancename $queue)" + return fi + local name=$(get_worker_name "$instancename" "$queue") + daemon --name="$name" \ + --pidfiles="/var/run/koha/$instancename/" \ + --user="$instancename-koha.$instancename-koha" \ + --running } get_worker_name() @@ -317,14 +361,12 @@ is_plack_enabled() is_plack_running() { local instancename=$1 - - if start-stop-daemon --pidfile "/var/run/koha/${instancename}/plack.pid" \ - --user="$instancename-koha" \ - --status ; then - return 0 - else - return 1 + if [ "$(koha_init_backend)" = "systemd" ]; then + systemctl is-active --quiet "$(_koha_systemd_unit plack $instancename)" + return fi + start-stop-daemon --pidfile "/var/run/koha/${instancename}/plack.pid" \ + --user="$instancename-koha" --status } is_z3950_enabled() @@ -341,14 +383,12 @@ is_z3950_enabled() is_z3950_running() { local instancename=$1 - - if start-stop-daemon --pidfile "/var/run/koha/${instancename}/z3950-responder.pid" \ - --user="$instancename-koha" \ - --status ; then - return 0 - else - return 1 + if [ "$(koha_init_backend)" = "systemd" ]; then + systemctl is-active --quiet "$(_koha_systemd_unit z3950 $instancename)" + return fi + start-stop-daemon --pidfile "/var/run/koha/${instancename}/z3950-responder.pid" \ + --user="$instancename-koha" --status } is_elasticsearch_enabled() @@ -512,3 +552,772 @@ get_es_indexer_batch_size() echo "10" fi } + +# --- Legacy (SysV) lifecycle functions --- +# These are the fallback implementations used when systemd is not available. +# They rely on globals set by the calling script (e.g. $STARMAN, $ZEBRA_DAEMON, +# $worker_DAEMON, $verbose, $debugger, etc.) + +_sysv_start_plack() +{ + local instancename=$1 + + local PIDFILE="/var/run/koha/${instancename}/plack.pid" + local PLACKSOCKET="/var/run/koha/${instancename}/plack.sock" + local PSGIFILE="/etc/koha/plack.psgi" + local NAME="${instancename}-koha-plack" + + if [ -e "/etc/koha/sites/${instancename}/plack.psgi" ]; then + PSGIFILE="/etc/koha/sites/${instancename}/plack.psgi" + fi + + _check_and_fix_plack_perms $instancename + + PLACK_MAX_REQUESTS=$(run_safe_xmlstarlet $instancename plack_max_requests) + [ -z $PLACK_MAX_REQUESTS ] && PLACK_MAX_REQUESTS="50" + PLACK_WORKERS=$(run_safe_xmlstarlet $instancename plack_workers) + [ -z $PLACK_WORKERS ] && PLACK_WORKERS="2" + + instance_user="${instancename}-koha" + + if is_debug_mode ${instancename} || [ -n "$development_environment" ]; then + environment="development" + else + environment="deployment" + fi + daemonize="--daemonize" + logging="--access-log /var/log/koha/${instancename}/plack.log \ + --error-log /var/log/koha/${instancename}/plack-error.log" + max_requests_and_workers="--max-requests ${PLACK_MAX_REQUESTS} --workers ${PLACK_WORKERS}" + + if [ "$debugger" = "yes" ] && [ "$environment" = "development" ]; then + daemonize="" + logging="" + max_requests_and_workers="--workers 1" + STARMAN="/usr/bin/perl -d ${STARMAN}" + fi + + STARMANOPTS="-M FindBin ${max_requests_and_workers} \ + --user=${instance_user} --group ${instancename}-koha \ + --pid ${PIDFILE} ${daemonize} ${logging} \ + -E ${environment} --socket ${PLACKSOCKET} ${PSGIFILE}" + + if ! is_plack_running ${instancename}; then + export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml" + + log_daemon_msg "Starting Plack daemon for ${instancename}" + + current_dir=$(pwd) + eval cd ~$instance_user + + if ${STARMAN} ${STARMANOPTS}; then + log_end_msg 0 + else + log_end_msg 1 + fi + cd "$current_dir" + else + log_daemon_msg "Error: Plack already running for ${instancename}" + log_end_msg 1 + fi +} + +_sysv_stop_plack() +{ + local instancename=$1 + local PIDFILE="/var/run/koha/${instancename}/plack.pid" + + if is_plack_running ${instancename}; then + log_daemon_msg "Stopping Plack daemon for ${instancename}" + if start-stop-daemon --pidfile ${PIDFILE} --user="${instancename}-koha" --stop --retry=QUIT/30/KILL/5; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_daemon_msg "Error: Plack not running for ${instancename}" + log_end_msg 1 + fi +} + +_sysv_restart_plack() +{ + local instancename=$1 + + if is_plack_running ${instancename}; then + _sysv_stop_plack $instancename && _sysv_start_plack $instancename + else + log_warning_msg "Plack not running for ${instancename}." + _sysv_start_plack $instancename + fi +} + +_sysv_reload_plack() +{ + local instancename=$1 + local PIDFILE="/var/run/koha/${instancename}/plack.pid" + + if is_plack_running ${instancename}; then + log_daemon_msg "Reloading Plack daemon for ${instancename}" + if start-stop-daemon --pidfile ${PIDFILE} --user="${instancename}-koha" --stop --signal HUP; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_daemon_msg "Error: Plack not running for ${instancename}" + log_end_msg 1 + fi +} + +_sysv_plack_status() +{ + local name=$1 + + if is_plack_running ${name}; then + log_daemon_msg "Plack running for ${name}" + log_end_msg 0 + else + log_daemon_msg "Plack not running for ${name}" + log_end_msg 3 + fi +} + +_check_and_fix_plack_perms() +{ + local instance=$1 + local files="/var/log/koha/${instance}/plack.log \ + /var/log/koha/${instance}/plack-error.log" + for file in ${files}; do + if [ ! -e "${file}" ]; then + touch ${file} + fi + chown "${instance}-koha":"${instance}-koha" ${file} + done +} + +_sysv_start_zebra() +{ + local name=$1 + local loglevels=$(get_loglevels ${name}) + local max_record_size=$(get_max_record_size ${name}) + + if ! is_zebra_running $name; then + _check_and_fix_zebra_perms ${name} + + DAEMONOPTS="--name=${name}-koha-zebra \ + --pidfiles=/var/run/koha/${name}/ \ + --errlog=/var/log/koha/${name}/zebra-error.log \ + --output=/var/log/koha/${name}/zebra-output.log \ + --verbose=1 --respawn --delay=30 \ + --user=${name}-koha.${name}-koha" + + ZEBRA_PARAMS="-v $loglevels \ + -k $max_record_size \ + -f /etc/koha/sites/${name}/koha-conf.xml" + ZEBRA_TIMEFORMAT='%FT%T' + + [ "$verbose" != "no" ] && \ + log_daemon_msg "Starting Koha Zebra daemon for ${name}" + + if daemon $DAEMONOPTS -- $ZEBRA_DAEMON $ZEBRA_PARAMS -m "$ZEBRA_TIMEFORMAT"; then + ([ "$verbose" != "no" ] && log_end_msg 0) || return 0 + else + ([ "$verbose" != "no" ] && log_end_msg 1) || return 1 + fi + else + if [ "$verbose" != "no" ]; then + log_daemon_msg "Error: Zebra already running for ${name}" + log_end_msg 1 + else + return 1 + fi + fi +} + +_sysv_stop_zebra() +{ + local name=$1 + + if is_zebra_running $name; then + DAEMONOPTS="--name=${name}-koha-zebra \ + --pidfiles=/var/run/koha/${name}/ \ + --errlog=/var/log/koha/${name}/zebra-error.log \ + --output=/var/log/koha/${name}/zebra-output.log \ + --verbose=1 --respawn --delay=30 \ + --user=${name}-koha.${name}-koha" + + [ "$verbose" != "no" ] && \ + log_daemon_msg "Stopping Koha Zebra daemon for ${name}" + + if daemon $DAEMONOPTS --stop -- $ZEBRA_DAEMON $ZEBRA_PARAMS; then + ([ "$verbose" != "no" ] && log_end_msg 0) || return 0 + else + ([ "$verbose" != "no" ] && log_end_msg 1) || return 1 + fi + else + if [ "$verbose" != "no" ]; then + log_daemon_msg "Error: Zebra not running for ${name}" + log_end_msg 1 + else + return 1 + fi + fi +} + +_sysv_restart_zebra() +{ + local name=$1 + + if is_zebra_running ${name}; then + local noLF="-n" + [ "$verbose" != "no" ] && noLF="" + echo $noLF `_sysv_stop_zebra ${name}` + echo $noLF `_sysv_start_zebra ${name}` + else + if [ "$verbose" != "no" ]; then + log_warning_msg "Zebra not running for ${name}." + fi + _sysv_start_zebra ${name} + fi +} + +_sysv_zebra_status() +{ + local name=$1 + + if is_zebra_running ${name}; then + log_daemon_msg "Zebra running for ${name}" + log_end_msg 0 + else + log_daemon_msg "Zebra not running for ${name}" + log_end_msg 3 + fi +} + +_check_and_fix_zebra_perms() +{ + local name=$1 + local files="/var/log/koha/${name}/zebra-output.log \ + /var/log/koha/${name}/zebra-error.log" + for file in ${files}; do + if [ ! -e "${file}" ]; then + touch ${file} + fi + chown "${name}-koha":"${name}-koha" ${file} + done +} + +_sysv_start_worker() +{ + local name=$1 + local queues=$2 + local error_count=0 + + for queue in $queues; do + if ! is_worker_running "$name" "$queue"; then + worker_name=$(get_worker_name "$name" "$queue") + export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" + + DAEMONOPTS="--name=${worker_name} \ + --errlog=/var/log/koha/${name}/worker-error.log \ + --output=/var/log/koha/${name}/worker-output.log \ + --pidfiles=/var/run/koha/${name}/ \ + --verbose=1 --respawn --delay=30 \ + --user=${name}-koha.${name}-koha" + + echo "Starting Koha worker daemon for ${name} (${queue})" + if ! daemon $DAEMONOPTS -- "$worker_DAEMON" --queue "$queue"; then + ((error_count++)) + fi + else + echo "Error: worker already running for ${name} (${queue})" + ((error_count++)) + fi + done + log_end_msg $error_count +} + +_sysv_stop_worker() +{ + local name=$1 + local queues=$2 + local error_count=0 + + for queue in $queues; do + if is_worker_running "$name" "$queue"; then + export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" + worker_name=$(get_worker_name "$name" "$queue") + + DAEMONOPTS="--name=${worker_name} \ + --errlog=/var/log/koha/${name}/worker-error.log \ + --output=/var/log/koha/${name}/worker-output.log \ + --pidfiles=/var/run/koha/${name}/ \ + --verbose=1 --respawn --delay=30 \ + --user=${name}-koha.${name}-koha" + + echo "Stopping Koha worker daemon for ${name} (${queue})" + if ! daemon $DAEMONOPTS --stop -- "$worker_DAEMON" --queue "$queue"; then + ((error_count++)) + fi + else + echo "Error: worker not running for ${name} (${queue})" + ((error_count++)) + fi + done + log_end_msg $error_count +} + +_sysv_restart_worker() +{ + local name=$1 + local queues=$2 + local error_count=0 + + for queue in $queues; do + if is_worker_running "$name" "$queue"; then + export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" + worker_name=$(get_worker_name "$name" "$queue") + + DAEMONOPTS="--name=${worker_name} \ + --errlog=/var/log/koha/${name}/worker-error.log \ + --output=/var/log/koha/${name}/worker-output.log \ + --pidfiles=/var/run/koha/${name}/ \ + --verbose=1 --respawn --delay=30 \ + --user=${name}-koha.${name}-koha" + + echo "Restarting Koha worker daemon for ${name} (${queue})" + if ! daemon $DAEMONOPTS --restart -- "$worker_DAEMON" --queue "$queue"; then + ((error_count++)) + fi + else + echo "Worker not running for ${name} (${queue})." + _sysv_start_worker $name $queue + fi + done + log_end_msg $error_count +} + +_sysv_worker_status() +{ + local name=$1 + local queues=$2 + + for queue in $queues; do + if is_worker_running "$name" "$queue"; then + log_daemon_msg "worker running for ${name} (${queue})" + log_end_msg 0 + else + log_daemon_msg "worker not running for ${name} (${queue})" + log_end_msg 3 + fi + done +} + +_sysv_start_indexer() +{ + local name=$1 + + if ! is_indexer_running $name; then + export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" + + DAEMONOPTS="--name=$name-koha-indexer \ + --errlog=/var/log/koha/$name/indexer-error.log \ + --output=/var/log/koha/$name/indexer-output.log \ + --pidfiles=/var/run/koha/$name/ \ + --verbose=1 --respawn --delay=30 \ + --user=$name-koha.$name-koha" + + log_daemon_msg "Starting Koha indexing daemon for $name" + if daemon $DAEMONOPTS -- $INDEXER_DAEMON $INDEXER_PARAMS; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_daemon_msg "Error: Indexer already running for $name" + log_end_msg 1 + fi +} + +_sysv_stop_indexer() +{ + local name=$1 + + if is_indexer_running $name; then + export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" + + DAEMONOPTS="--name=$name-koha-indexer \ + --errlog=/var/log/koha/$name/indexer-error.log \ + --output=/var/log/koha/$name/indexer-output.log \ + --pidfiles=/var/run/koha/$name/ \ + --verbose=1 --respawn --delay=30 \ + --user=$name-koha.$name-koha" + + log_daemon_msg "Stopping Koha indexing daemon for $name" + if daemon $DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXER_PARAMS; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_daemon_msg "Error: Indexer not running for $name" + log_end_msg 1 + fi +} + +_sysv_restart_indexer() +{ + local name=$1 + + if is_indexer_running $name; then + export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" + + DAEMONOPTS="--name=$name-koha-indexer \ + --errlog=/var/log/koha/$name/indexer-error.log \ + --output=/var/log/koha/$name/indexer-output.log \ + --pidfiles=/var/run/koha/$name/ \ + --verbose=1 --respawn --delay=30 \ + --user=$name-koha.$name-koha" + + log_daemon_msg "Restarting Koha indexing daemon for $name" + if daemon $DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXER_PARAMS; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_warning_msg "Indexer not running for $name." + _sysv_start_indexer $name + fi +} + +_sysv_indexer_status() +{ + local name=$1 + + if is_indexer_running ${name}; then + log_daemon_msg "Indexer running for ${name}" + log_end_msg 0 + else + log_daemon_msg "Indexer not running for ${name}" + log_end_msg 3 + fi +} + +_sysv_start_es_indexer() +{ + local name=$1 + + if ! is_es_indexer_running $name; then + export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" + + DAEMONOPTS="--name=$name-koha-es-indexer \ + --errlog=/var/log/koha/$name/es-indexer-error.log \ + --output=/var/log/koha/$name/es-indexer-output.log \ + --pidfiles=/var/run/koha/$name/ \ + --verbose=1 --respawn --delay=30 \ + --user=$name-koha.$name-koha" + + log_daemon_msg "Starting Koha ES indexing daemon for $name" + if daemon $DAEMONOPTS -- $worker_DAEMON --batch_size ${batch_size}; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_daemon_msg "Error: ES indexing daemon already running for $name" + log_end_msg 1 + fi +} + +_sysv_stop_es_indexer() +{ + local name=$1 + + if is_es_indexer_running $name; then + export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" + + DAEMONOPTS="--name=$name-koha-es-indexer \ + --errlog=/var/log/koha/$name/es-indexer-error.log \ + --output=/var/log/koha/$name/es-indexer-output.log \ + --pidfiles=/var/run/koha/$name/ \ + --verbose=1 --respawn --delay=30 \ + --user=$name-koha.$name-koha" + + log_daemon_msg "Stopping Koha ES indexing daemon for $name" + if daemon $DAEMONOPTS --stop -- $worker_DAEMON; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_daemon_msg "Error: ES indexing daemon not running for $name" + log_end_msg 1 + fi +} + +_sysv_restart_es_indexer() +{ + local name=$1 + + if is_es_indexer_running $name; then + export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" + + DAEMONOPTS="--name=$name-koha-es-indexer \ + --errlog=/var/log/koha/$name/es-indexer-error.log \ + --output=/var/log/koha/$name/es-indexer-output.log \ + --pidfiles=/var/run/koha/$name/ \ + --verbose=1 --respawn --delay=30 \ + --user=$name-koha.$name-koha" + + log_daemon_msg "Restarting Koha ES indexing daemon for $name" + if daemon $DAEMONOPTS --restart -- $worker_DAEMON --batch_size ${batch_size}; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_warning_msg "ES indexing daemon not running for $name." + _sysv_start_es_indexer $name + fi +} + +_sysv_es_indexer_status() +{ + local name=$1 + + if is_es_indexer_running $name; then + log_daemon_msg "ES indexing daemon running for ${name}" + log_end_msg 0 + else + log_daemon_msg "ES indexing daemon not running for ${name}" + log_end_msg 3 + fi +} + +_sysv_start_sip() +{ + local name=$1 + + _check_and_fix_sip_perms $name + + if ! is_sip_running $name; then + if [ ! -f "/etc/koha/sites/${name}/SIPconfig.xml" ] || [ ! -f "/var/lib/koha/${name}/sip.enabled" ] ; then + echo "SIP is disabled, or you do not have a SIPconfig.xml file." + else + adjust_paths_git_install $name + export KOHA_HOME PERL5LIB + + if ! is_git_install $name; then + LIBDIR=$KOHA_HOME/lib + else + LIBDIR=$KOHA_HOME + fi + + DAEMONOPTS="--name=${name}-koha-sip \ + --errlog=/var/log/koha/${name}/sip-error.log \ + --output=/var/log/koha/${name}/sip-output.log \ + --verbose=1 --respawn --delay=30 \ + --pidfiles=/var/run/koha/${name} \ + --user=${name}-koha.${name}-koha" + + SIP_PARAMS="$LIBDIR/C4/SIP/SIPServer.pm \ + /etc/koha/sites/${name}/SIPconfig.xml" + + [ "$verbose" != "no" ] && \ + log_daemon_msg "Starting SIP server for ${name}" + + if daemon $DAEMONOPTS -- perl $SIP_PARAMS; then + ([ "$verbose" != "no" ] && log_end_msg 0) || return 0 + else + ([ "$verbose" != "no" ] && log_end_msg 1) || return 1 + fi + fi + else + if [ "$verbose" != "no" ]; then + log_daemon_msg "Warning: SIP server already running for ${name}" + log_end_msg 0 + else + return 0 + fi + fi +} + +_sysv_stop_sip() +{ + local name=$1 + local PIDFILE="/var/run/koha/${name}/${name}-koha-sip.pid" + + if is_sip_running $name; then + [ "$verbose" != "no" ] && \ + log_daemon_msg "Stopping SIP server for ${name}" + + if start-stop-daemon --pidfile $PIDFILE --user ${name}-koha --stop --retry=TERM/30/KILL/5; then + ([ "$verbose" != "no" ] && log_end_msg 0) || return 0 + else + ([ "$verbose" != "no" ] && log_end_msg 1) || return 1 + fi + else + if [ "$verbose" != "no" ]; then + log_daemon_msg "Warning: SIP server not running for ${name}" + log_end_msg 0 + else + return 0 + fi + fi +} + +_sysv_restart_sip() +{ + local name=$1 + + if is_sip_running ${name}; then + local noLF="-n" + [ "$verbose" != "no" ] && noLF="" + echo $noLF `_sysv_stop_sip ${name}` + + MAX_ITERATION=10 + while is_sip_running ${name}; do + i=$((i+1)) + if [ $MAX_ITERATION -lt $i ]; then + break + fi + sleep 1; + done + echo $noLF `_sysv_start_sip ${name}` + else + if [ "$verbose" != "no" ]; then + log_warning_msg "Warning: SIP server not running for ${name}." + fi + _sysv_start_sip ${name} + fi +} + +_sysv_sip_status() +{ + local name=$1 + + if is_sip_running ${name}; then + log_daemon_msg "SIP server running for ${name}" + log_end_msg 0 + else + log_daemon_msg "SIP server not running for ${name}" + log_end_msg 3 + fi +} + +_check_and_fix_sip_perms() +{ + local name=$1 + local files="/var/log/koha/${name}/sip-error.log /var/log/koha/${name}/sip-output.log" + for file in ${files}; do + if [ ! -e "${file}" ]; then + touch ${file} + fi + chown "${name}-koha":"${name}-koha" ${file} + done +} + +_sysv_start_z3950() +{ + local instancename=$1 + + local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid" + local NAME="${instancename}-koha-z3950-responder" + local CONFIGDIR="/etc/koha/z3950" + + if [ -e "/etc/koha/sites/${instancename}/z3950/config.xml" ]; then + CONFIGDIR="/etc/koha/sites/${instancename}/z3950" + fi + + _check_and_fix_z3950_perms $instancename + + instance_user="${instancename}-koha" + + daemonize="-D -d ${instancename}-koha-z3950" + logging="-l /var/log/koha/${instancename}/z3950.log" + + Z3950RESPONDER="/usr/bin/perl $KOHA_HOME/$KOHA_BINDIR/z3950_responder.pl" + if [ "$debugger" = "yes" ] && is_debug_mode $instancename; then + daemonize="" + logging="" + Z3950RESPONDER="/usr/bin/perl -d $KOHA_HOME/$KOHA_BINDIR/z3950_responder.pl" + elif [ "$debugger" = "yes" ]; then + warn "Not a test system, disabling debugger" + fi + + Z3950OPTS="-c ${CONFIGDIR} \ + -u ${instance_user} \ + -p ${PIDFILE} ${daemonize} ${logging}" + + if ! is_z3950_running ${instancename}; then + export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml" + + if [[ ! $Z3950_ADDITIONAL_OPTS ]]; then + Z3950_ADDITIONAL_OPTS="$( xmlstarlet sel -t -v 'yazgfs/config/z3950_responder_options' "$CONFIGDIR/config.xml" || true )" + fi + + log_daemon_msg "Starting Z39.50/SRU daemon for ${instancename}" + + current_dir=$(pwd) + eval cd ~$instance_user + + if ${Z3950RESPONDER} ${Z3950_ADDITIONAL_OPTS} ${Z3950OPTS}; then + log_end_msg 0 + else + log_end_msg 1 + fi + cd "$current_dir" + else + log_daemon_msg "Error: Z39.50/SRU already running for ${instancename}" + log_end_msg 1 + fi +} + +_sysv_stop_z3950() +{ + local instancename=$1 + local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid" + + if is_z3950_running ${instancename}; then + log_daemon_msg "Stopping Z39.50/SRU daemon for ${instancename}" + if start-stop-daemon --pidfile ${PIDFILE} --stop --retry=TERM/30/KILL/5; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_daemon_msg "Error: Z39.50/SRU not running for ${instancename}" + log_end_msg 1 + fi +} + +_sysv_restart_z3950() +{ + local instancename=$1 + + if is_z3950_running ${instancename}; then + log_daemon_msg "Restarting Z39.50/SRU daemon for ${instancename}" + if _sysv_stop_z3950 $instancename && _sysv_start_z3950 $instancename; then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_warning_msg "Z39.50/SRU not running for ${instancename}." + _sysv_start_z3950 $instancename + fi +} + +_check_and_fix_z3950_perms() +{ + local instance=$1 + local files="/var/log/koha/${instance}/z3950.log" + for file in ${files}; do + if [ ! -e "${file}" ]; then + touch ${file} + fi + chown "${instance}-koha":"${instance}-koha" ${file} + done +} diff --git a/debian/scripts/koha-indexer b/debian/scripts/koha-indexer index f85f841bfc..40aaf964a4 100755 --- a/debian/scripts/koha-indexer +++ b/debian/scripts/koha-indexer @@ -58,94 +58,40 @@ EOF start_indexer() { local name=$1 - - if ! is_indexer_running $name; then - export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - - DAEMONOPTS="--name=$name-koha-indexer \ - --errlog=/var/log/koha/$name/indexer-error.log \ - --output=/var/log/koha/$name/indexer-output.log \ - --pidfiles=/var/run/koha/$name/ \ - --verbose=1 --respawn --delay=30 \ - --user=$name-koha.$name-koha" - - log_daemon_msg "Starting Koha indexing daemon for $name" - - if daemon $DAEMONOPTS -- $INDEXER_DAEMON $INDEXER_PARAMS; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl start indexer "$name" else - log_daemon_msg "Error: Indexer already running for $name" - log_end_msg 1 + _sysv_start_indexer "$name" fi } stop_indexer() { local name=$1 - - if is_indexer_running $name; then - export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - - DAEMONOPTS="--name=$name-koha-indexer \ - --errlog=/var/log/koha/$name/indexer-error.log \ - --output=/var/log/koha/$name/indexer-output.log \ - --pidfiles=/var/run/koha/$name/ \ - --verbose=1 --respawn --delay=30 \ - --user=$name-koha.$name-koha" - - log_daemon_msg "Stopping Koha indexing daemon for $name" - - if daemon $DAEMONOPTS --stop -- $INDEXER_DAEMON $INDEXER_PARAMS; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl stop indexer "$name" else - log_daemon_msg "Error: Indexer not running for $name" - log_end_msg 1 + _sysv_stop_indexer "$name" fi } restart_indexer() { local name=$1 - - if is_indexer_running $name; then - export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" - - DAEMONOPTS="--name=$name-koha-indexer \ - --errlog=/var/log/koha/$name/indexer-error.log \ - --output=/var/log/koha/$name/indexer-output.log \ - --pidfiles=/var/run/koha/$name/ \ - --verbose=1 --respawn --delay=30 \ - --user=$name-koha.$name-koha" - - log_daemon_msg "Restarting Koha indexing daemon for $name" - - if daemon $DAEMONOPTS --restart -- $INDEXER_DAEMON $INDEXER_PARAMS; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl restart indexer "$name" else - log_warning_msg "Indexer not running for $name." - start_indexer $name + _sysv_restart_indexer "$name" fi } indexer_status() { local name=$1 - - if is_indexer_running ${name}; then - log_daemon_msg "Indexer running for ${name}" - log_end_msg 0 + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl status indexer "$name" else - log_daemon_msg "Indexer not running for ${name}" - log_end_msg 3 + _sysv_indexer_status "$name" fi } diff --git a/debian/scripts/koha-plack b/debian/scripts/koha-plack index ee3586dbb2..3b3dac0399 100755 --- a/debian/scripts/koha-plack +++ b/debian/scripts/koha-plack @@ -72,137 +72,50 @@ EOF start_plack() { local instancename=$1 - - local PIDFILE="/var/run/koha/${instancename}/plack.pid" - local PLACKSOCKET="/var/run/koha/${instancename}/plack.sock" - local PSGIFILE="/etc/koha/plack.psgi" - local NAME="${instancename}-koha-plack" - - if [ -e "/etc/koha/sites/${instancename}/plack.psgi" ]; then - # pick instance-specific psgi file - PSGIFILE="/etc/koha/sites/${instancename}/plack.psgi" - fi # else stick with the default one - - _check_and_fix_perms $instancename - - PLACK_MAX_REQUESTS=$(run_safe_xmlstarlet $instancename plack_max_requests) - [ -z $PLACK_MAX_REQUESTS ] && PLACK_MAX_REQUESTS="50" - PLACK_WORKERS=$(run_safe_xmlstarlet $instancename plack_workers) - [ -z $PLACK_WORKERS ] && PLACK_WORKERS="2" - - instance_user="${instancename}-koha" - - if is_debug_mode ${instancename} || [ -n "$development_environment" ]; then - environment="development" + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl start plack "$instancename" else - environment="deployment" - fi - daemonize="--daemonize" - logging="--access-log /var/log/koha/${instancename}/plack.log \ - --error-log /var/log/koha/${instancename}/plack-error.log" - max_requests_and_workers="--max-requests ${PLACK_MAX_REQUESTS} --workers ${PLACK_WORKERS}" - - # Enable debugger? - if [ "$debugger" = "yes" ] && [ "$environment" = "development" ]; then - daemonize="" - logging="" # remote debugger takes care - max_requests_and_workers="--workers 1" - STARMAN="/usr/bin/perl -d ${STARMAN}" - fi - - STARMANOPTS="-M FindBin ${max_requests_and_workers} \ - --user=${instance_user} --group ${instancename}-koha \ - --pid ${PIDFILE} ${daemonize} ${logging} \ - -E ${environment} --socket ${PLACKSOCKET} ${PSGIFILE}" - - if ! is_plack_running ${instancename}; then - export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml" - - log_daemon_msg "Starting Plack daemon for ${instancename}" - - # Change to the instance's user dir - current_dir=$(pwd) - eval cd ~$instance_user - - if ${STARMAN} ${STARMANOPTS}; then - log_end_msg 0 - else - log_end_msg 1 - fi - # Go back to the original dir - cd "$current_dir" - - else - log_daemon_msg "Error: Plack already running for ${instancename}" - log_end_msg 1 + _sysv_start_plack "$instancename" fi } stop_plack() { local instancename=$1 - - local PIDFILE="/var/run/koha/${instancename}/plack.pid" - - if is_plack_running ${instancename}; then - - log_daemon_msg "Stopping Plack daemon for ${instancename}" - - if start-stop-daemon --pidfile ${PIDFILE} --user="${instancename}-koha" --stop --retry=QUIT/30/KILL/5; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl stop plack "$instancename" else - log_daemon_msg "Error: Plack not running for ${instancename}" - log_end_msg 1 + _sysv_stop_plack "$instancename" fi } restart_plack() { local instancename=$1 - - local PIDFILE="/var/run/koha/${instancename}/plack.pid" - - if is_plack_running ${instancename}; then - stop_plack $instancename && start_plack $instancename + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl restart plack "$instancename" else - log_warning_msg "Plack not running for ${instancename}." - start_plack $instancename + _sysv_restart_plack "$instancename" fi } reload_plack() { local instancename=$1 - - local PIDFILE="/var/run/koha/${instancename}/plack.pid" - - if is_plack_running ${instancename}; then - log_daemon_msg "Reloading Plack daemon for ${instancename}" - - if start-stop-daemon --pidfile ${PIDFILE} --user="${instancename}-koha" --stop --signal HUP; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl reload plack "$instancename" else - log_daemon_msg "Error: Plack not running for ${instancename}" - log_end_msg 1 + _sysv_reload_plack "$instancename" fi } plack_status() { local name=$1 - - if is_plack_running ${name}; then - log_daemon_msg "Plack running for ${name}" - log_end_msg 0 + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl status plack "$name" else - log_daemon_msg "Plack not running for ${name}" - log_end_msg 3 + _sysv_plack_status "$name" fi } @@ -340,21 +253,6 @@ EOM fi } -_check_and_fix_perms() -{ - local instance=$1 - - local files="/var/log/koha/${instance}/plack.log \ - /var/log/koha/${instance}/plack-error.log" - - for file in ${files} - do - if [ ! -e "${file}" ]; then - touch ${file} - fi - chown "${instance}-koha":"${instance}-koha" ${file} - done -} set_action() { diff --git a/debian/scripts/koha-sip b/debian/scripts/koha-sip index 73f56a0316..d2fdbf4e8a 100755 --- a/debian/scripts/koha-sip +++ b/debian/scripts/koha-sip @@ -60,122 +60,40 @@ EOF start_sip() { local name=$1 - - _check_and_fix_perms $name - - if ! is_sip_running $name; then - if [ ! -f "/etc/koha/sites/${name}/SIPconfig.xml" ] || [ ! -f "/var/lib/koha/${name}/sip.enabled" ] ; then - echo "SIP is disabled, or you do not have a SIPconfig.xml file." - else - adjust_paths_git_install $name - export KOHA_HOME PERL5LIB - - if ! is_git_install $name; then - LIBDIR=$KOHA_HOME/lib - else - LIBDIR=$KOHA_HOME - fi - - DAEMONOPTS="--name=${name}-koha-sip \ - --errlog=/var/log/koha/${name}/sip-error.log \ - --output=/var/log/koha/${name}/sip-output.log \ - --verbose=1 \ - --respawn \ - --delay=30 \ - --pidfiles=/var/run/koha/${name} \ - --user=${name}-koha.${name}-koha" - - SIP_PARAMS="$LIBDIR/C4/SIP/SIPServer.pm \ - /etc/koha/sites/${name}/SIPconfig.xml" - - [ "$verbose" != "no" ] && \ - log_daemon_msg "Starting SIP server for ${name}" - - if daemon $DAEMONOPTS -- perl $SIP_PARAMS; then - ([ "$verbose" != "no" ] && \ - log_end_msg 0) || return 0 - else - ([ "$verbose" != "no" ] && \ - log_end_msg 1) || return 1 - fi - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl start sip "$name" else - if [ "$verbose" != "no" ]; then - log_daemon_msg "Warning: SIP server already running for ${name}" - log_end_msg 0 - else - return 0 - fi + _sysv_start_sip "$name" fi } stop_sip() { local name=$1 - local PIDFILE="/var/run/koha/${name}/${name}-koha-sip.pid" - - if is_sip_running $name; then - - [ "$verbose" != "no" ] && \ - log_daemon_msg "Stopping SIP server for ${name}" - - if start-stop-daemon --pidfile $PIDFILE --user ${name}-koha --stop --retry=TERM/30/KILL/5; then - ([ "$verbose" != "no" ] && \ - log_end_msg 0) || return 0 - else - ([ "$verbose" != "no" ] && \ - log_end_msg 1) || return 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl stop sip "$name" else - if [ "$verbose" != "no" ]; then - log_daemon_msg "Warning: SIP server not running for ${name}" - log_end_msg 0 - else - return 0 - fi + _sysv_stop_sip "$name" fi } restart_sip() { local name=$1 - - if is_sip_running ${name}; then - local noLF="-n" - [ "$verbose" != "no" ] && noLF="" - echo $noLF `stop_sip ${name}` - - MAX_ITERATION=10 - while is_sip_running ${name}; do - i=$((i+1)) - if [ $MAX_ITERATION -lt $i ]; then - break - fi - sleep 1; - - done - echo $noLF `start_sip ${name}` + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl restart sip "$name" else - if [ "$verbose" != "no" ]; then - log_warning_msg "Warning: SIP server not running for ${name}." - start_sip ${name} - else - start_sip ${name} - return 0 - fi + _sysv_restart_sip "$name" fi } sip_status() { local name=$1 - - if is_sip_running ${name}; then - log_daemon_msg "SIP server running for ${name}" - log_end_msg 0 + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl status sip "$name" else - log_daemon_msg "SIP server not running for ${name}" - log_end_msg 3 + _sysv_sip_status "$name" fi } @@ -217,21 +135,6 @@ disable_sip() } -_check_and_fix_perms() -{ - local name=$1 - - local files="/var/log/koha/${name}/sip-error.log /var/log/koha/${name}/sip-output.log" - - for file in ${files} - do - if [ ! -e "${file}" ]; then - touch ${file} - fi - chown "${name}-koha":"${name}-koha" ${file} - done -} - set_action() { if [ "$op" = "" ]; then diff --git a/debian/scripts/koha-worker b/debian/scripts/koha-worker index 7e4743d6fc..a2ee757a2b 100755 --- a/debian/scripts/koha-worker +++ b/debian/scripts/koha-worker @@ -64,118 +64,52 @@ start_worker() { local name=$1 local queues=$2 - - local error_count=0 - - for queue in $queues; do - if ! is_worker_running "$name" "$queue"; then - - worker_name=$(get_worker_name "$name" "$queue") - export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" - - DAEMONOPTS="--name=${worker_name} \ - --errlog=/var/log/koha/${name}/worker-error.log \ - --output=/var/log/koha/${name}/worker-output.log \ - --pidfiles=/var/run/koha/${name}/ \ - --verbose=1 --respawn --delay=30 \ - --user=${name}-koha.${name}-koha" - - echo "Starting Koha worker daemon for ${name} (${queue})" - - if ! daemon $DAEMONOPTS -- "$worker_DAEMON" --queue "$queue"; then - ((error_count++)) - fi - else - echo "Error: worker already running for ${name} (${queue})" - ((error_count++)) - fi - done - - log_end_msg $error_count + if [ "$(koha_init_backend)" = "systemd" ]; then + for queue in $queues; do + koha_service_ctl start worker "$name" "$queue" + done + else + _sysv_start_worker "$name" "$queues" + fi } stop_worker() { local name=$1 local queues=$2 - - local error_count=0 - - for queue in $queues; do - if is_worker_running "$name" "$queue"; then - export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" - - worker_name=$(get_worker_name "$name" "$queue") - - DAEMONOPTS="--name=${worker_name} \ - --errlog=/var/log/koha/${name}/worker-error.log \ - --output=/var/log/koha/${name}/worker-output.log \ - --pidfiles=/var/run/koha/${name}/ \ - --verbose=1 --respawn --delay=30 \ - --user=${name}-koha.${name}-koha" - - echo "Stopping Koha worker daemon for ${name} (${queue})" - - if ! daemon $DAEMONOPTS --stop -- "$worker_DAEMON" --queue "$queue"; then - ((error_count++)) - fi - else - echo "Error: worker not running for ${name} (${queue})" - ((error_count++)) - fi - done - - log_end_msg $error_count + if [ "$(koha_init_backend)" = "systemd" ]; then + for queue in $queues; do + koha_service_ctl stop worker "$name" "$queue" + done + else + _sysv_stop_worker "$name" "$queues" + fi } restart_worker() { local name=$1 local queues=$2 - - local error_count=0 - - for queue in $queues; do - if is_worker_running "$name" "$queue"; then - export KOHA_CONF="/etc/koha/sites/${name}/koha-conf.xml" - - worker_name=$(get_worker_name "$name" "$queue") - - DAEMONOPTS="--name=${worker_name} \ - --errlog=/var/log/koha/${name}/worker-error.log \ - --output=/var/log/koha/${name}/worker-output.log \ - --pidfiles=/var/run/koha/${name}/ \ - --verbose=1 --respawn --delay=30 \ - --user=${name}-koha.${name}-koha" - - echo "Restarting Koha worker daemon for ${name} (${queue})" - - if ! daemon $DAEMONOPTS --restart -- "$worker_DAEMON" --queue "$queue"; then - ((error_count++)) - fi - else - echo "Worker not running for ${name} (${queue})." - start_worker $name $queue - fi - done - - log_end_msg $error_count + if [ "$(koha_init_backend)" = "systemd" ]; then + for queue in $queues; do + koha_service_ctl restart worker "$name" "$queue" + done + else + _sysv_restart_worker "$name" "$queues" + fi } worker_status() { local name=$1 local queues=$2 - - for queue in $queues; do - if is_worker_running "$name" "$queue"; then - log_daemon_msg "worker running for ${name} (${queue})" - log_end_msg 0 - else - log_daemon_msg "worker not running for ${name} (${queue})" - log_end_msg 3 - fi - done + if [ "$(koha_init_backend)" = "systemd" ]; then + for queue in $queues; do + koha_service_ctl status worker "$name" "$queue" + done + else + _sysv_worker_status "$name" "$queues" + fi } set_action() diff --git a/debian/scripts/koha-z3950-responder b/debian/scripts/koha-z3950-responder index 5642f2c89f..4a5cb41884 100755 --- a/debian/scripts/koha-z3950-responder +++ b/debian/scripts/koha-z3950-responder @@ -68,102 +68,30 @@ EOF start_z3950() { local instancename=$1 - - local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid" - local NAME="${instancename}-koha-z3950-responder" - local CONFIGDIR="/etc/koha/z3950" - - if [ -e "/etc/koha/sites/${instancename}/z3950/config.xml" ]; then - # pick instance-specific config dir - CONFIGDIR="/etc/koha/sites/${instancename}/z3950" - fi # else stick with the default one - - _check_and_fix_perms $instancename - - instance_user="${instancename}-koha" - - daemonize="-D -d ${instancename}-koha-z3950" - logging="-l /var/log/koha/${instancename}/z3950.log" - - Z3950RESPONDER="/usr/bin/perl $KOHA_HOME/$KOHA_BINDIR/z3950_responder.pl" - if [ "$debugger" = "yes" ] && is_debug_mode $instancename; then - daemonize="" - logging="" # remote debugger takes care - Z3950RESPONDER="/usr/bin/perl -d $KOHA_HOME/$KOHA_BINDIR/z3950_responder.pl" - elif [ "$debugger" = "yes" ]; then - warn "Not a test system, disabling debugger" - fi - - Z3950OPTS="-c ${CONFIGDIR} \ - -u ${instance_user} \ - -p ${PIDFILE} ${daemonize} ${logging}" - - if ! is_z3950_running ${instancename}; then - export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml" - - if [[ ! $Z3950_ADDITIONAL_OPTS ]]; then - Z3950_ADDITIONAL_OPTS="$( xmlstarlet sel -t -v 'yazgfs/config/z3950_responder_options' "$CONFIGDIR/config.xml" || true )" - fi - - log_daemon_msg "Starting Z39.50/SRU daemon for ${instancename}" - - # Change to the instance's user dir - current_dir=$(pwd) - eval cd ~$instance_user - - if ${Z3950RESPONDER} ${Z3950_ADDITIONAL_OPTS} ${Z3950OPTS}; then - log_end_msg 0 - else - log_end_msg 1 - fi - # Go back to the original dir - cd "$current_dir" - + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl start z3950 "$instancename" else - log_daemon_msg "Error: Z39.50/SRU already running for ${instancename}" - log_end_msg 1 + _sysv_start_z3950 "$instancename" fi } stop_z3950() { local instancename=$1 - - local PIDFILE="/var/run/koha/${instancename}/z3950-responder.pid" - - if is_z3950_running ${instancename}; then - - log_daemon_msg "Stopping Z39.50/SRU daemon for ${instancename}" - - if start-stop-daemon --pidfile ${PIDFILE} --stop --retry=TERM/30/KILL/5; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl stop z3950 "$instancename" else - log_daemon_msg "Error: Z39.50/SRU not running for ${instancename}" - log_end_msg 1 + _sysv_stop_z3950 "$instancename" fi } restart_z3950() { local instancename=$1 - - local PIDFILE="/var/run/koha/${instancename}/z3950.pid" - - if is_z3950_running ${instancename}; then - - log_daemon_msg "Restarting Z39.50/SRU daemon for ${instancename}" - - if stop_z3950 $instancename && start_z3950 $instancename; then - log_end_msg 0 - else - log_end_msg 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl restart z3950 "$instancename" else - log_warning_msg "Z39.50/SRU not running for ${instancename}." - start_z3950 $instancename + _sysv_restart_z3950 "$instancename" fi } @@ -211,21 +139,6 @@ disable_z3950() fi } -_check_and_fix_perms() -{ - local instance=$1 - - local files="/var/log/koha/${instance}/z3950.log" - - for file in ${files} - do - if [ ! -e "${file}" ]; then - touch ${file} - fi - chown "${instance}-koha":"${instance}-koha" ${file} - done -} - set_action() { if [ "$op" = "" ]; then diff --git a/debian/scripts/koha-zebra b/debian/scripts/koha-zebra index 2185fa0e4a..7eee7aced6 100755 --- a/debian/scripts/koha-zebra +++ b/debian/scripts/koha-zebra @@ -58,132 +58,43 @@ EOF start_zebra() { local name=$1 - - # get zebra log levels from koha-conf.xml - local loglevels=$(get_loglevels ${name}) - local max_record_size=$(get_max_record_size ${name}) - - if ! is_zebra_running $name; then - - _check_and_fix_perms ${name} - - DAEMONOPTS="--name=${name}-koha-zebra \ - --pidfiles=/var/run/koha/${name}/ \ - --errlog=/var/log/koha/${name}/zebra-error.log \ - --output=/var/log/koha/${name}/zebra-output.log \ - --verbose=1 \ - --respawn \ - --delay=30 \ - --user=${name}-koha.${name}-koha" - - ZEBRA_PARAMS="-v $loglevels \ - -k $max_record_size \ - -f /etc/koha/sites/${name}/koha-conf.xml" - ZEBRA_TIMEFORMAT='%FT%T' - - [ "$verbose" != "no" ] && \ - log_daemon_msg "Starting Koha Zebra daemon for ${name}" - - if daemon $DAEMONOPTS -- $ZEBRA_DAEMON $ZEBRA_PARAMS -m "$ZEBRA_TIMEFORMAT"; then - ([ "$verbose" != "no" ] && \ - log_end_msg 0) || return 0 - else - ([ "$verbose" != "no" ] && \ - log_end_msg 1) || return 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl start zebra "$name" else - if [ "$verbose" != "no" ]; then - log_daemon_msg "Error: Zebra already running for ${name}" - log_end_msg 1 - else - return 1 - fi + _sysv_start_zebra "$name" fi } stop_zebra() { local name=$1 - - if is_zebra_running $name; then - - DAEMONOPTS="--name=${name}-koha-zebra \ - --pidfiles=/var/run/koha/${name}/ \ - --errlog=/var/log/koha/${name}/zebra-error.log \ - --output=/var/log/koha/${name}/zebra-output.log \ - --verbose=1 \ - --respawn \ - --delay=30 \ - --user=${name}-koha.${name}-koha" - - [ "$verbose" != "no" ] && \ - log_daemon_msg "Stopping Koha Zebra daemon for ${name}" - - if daemon $DAEMONOPTS --stop -- $ZEBRA_DAEMON $ZEBRA_PARAMS; then - ([ "$verbose" != "no" ] && \ - log_end_msg 0) || return 0 - else - ([ "$verbose" != "no" ] && \ - log_end_msg 1) || return 1 - fi + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl stop zebra "$name" else - if [ "$verbose" != "no" ]; then - log_daemon_msg "Error: Zebra not running for ${name}" - log_end_msg 1 - else - return 1 - fi + _sysv_stop_zebra "$name" fi } restart_zebra() { local name=$1 - - if is_zebra_running ${name}; then - local noLF="-n" - [ "$verbose" != "no" ] && noLF="" - echo $noLF `stop_zebra ${name}` - echo $noLF `start_zebra ${name}` + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl restart zebra "$name" else - if [ "$verbose" != "no" ]; then - log_warning_msg "Zebra not running for ${name}." - start_zebra ${name} - else - start_zebra ${name} - return 0 - fi + _sysv_restart_zebra "$name" fi } zebra_status() { local name=$1 - - if is_zebra_running ${name}; then - log_daemon_msg "Zebra running for ${name}" - log_end_msg 0 + if [ "$(koha_init_backend)" = "systemd" ]; then + koha_service_ctl status zebra "$name" else - log_daemon_msg "Zebra not running for ${name}" - log_end_msg 3 + _sysv_zebra_status "$name" fi } -_check_and_fix_perms() -{ - local name=$1 - - local files="/var/log/koha/${name}/zebra-output.log \ - /var/log/koha/${name}/zebra-error.log" - - for file in ${files} - do - if [ ! -e "${file}" ]; then - touch ${file} - fi - chown "${name}-koha":"${name}-koha" ${file} - done -} set_action() {