Tomas Cohen Arazi
65542edbe0
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
243 lines
6.3 KiB
Bash
Executable file
243 lines
6.3 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# Copyright 2020 Koha Development team
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
set -e
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
# Read configuration variable file if it is present
|
|
[ -r /etc/default/koha-common ] && . /etc/default/koha-common
|
|
|
|
# include helper functions
|
|
if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
|
|
. "/usr/share/koha/bin/koha-functions.sh"
|
|
else
|
|
echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
usage()
|
|
{
|
|
local scriptname=$(basename $0)
|
|
|
|
cat <<EOF
|
|
$scriptname
|
|
|
|
This script lets you manage the worker daemon for your Koha instances.
|
|
|
|
Usage:
|
|
$scriptname [--start|--stop|--restart] [--quiet|-q] instancename1 [instancename2...]
|
|
$scriptname --status instancename1 [instancename2...]
|
|
$scriptname -h|--help
|
|
|
|
--start Start the worker daemon for the specified instances
|
|
--stop Stop the worker daemon for the specified instances
|
|
--restart Restart the worker daemon for the specified instances
|
|
--status Show the status of the worker for the specified instances
|
|
--quiet|-q Make the script quiet about non existent instance names
|
|
(useful for calling from another scripts).
|
|
--help|-h Display this help message
|
|
|
|
EOF
|
|
}
|
|
|
|
start_worker()
|
|
{
|
|
local name=$1
|
|
|
|
if ! is_worker_running $name; then
|
|
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
|
|
|
|
DAEMONOPTS="--name=$name-koha-worker \
|
|
--errlog=/var/log/koha/$name/worker-error.log \
|
|
--stdout=/var/log/koha/$name/worker.log \
|
|
--output=/var/log/koha/$name/worker-output.log \
|
|
--pidfiles=/var/run/koha/$name/ \
|
|
--verbose=1 --respawn --delay=30 \
|
|
--user=$name-koha.$name-koha"
|
|
|
|
log_daemon_msg "Starting Koha worker daemon for $name"
|
|
|
|
if daemon $DAEMONOPTS -- $worker_DAEMON; then
|
|
log_end_msg 0
|
|
else
|
|
log_end_msg 1
|
|
fi
|
|
else
|
|
log_daemon_msg "Error: worker already running for $name"
|
|
log_end_msg 1
|
|
fi
|
|
}
|
|
|
|
stop_worker()
|
|
{
|
|
local name=$1
|
|
|
|
if is_worker_running $name; then
|
|
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
|
|
|
|
DAEMONOPTS="--name=$name-koha-worker \
|
|
--errlog=/var/log/koha/$name/worker-error.log \
|
|
--stdout=/var/log/koha/$name/worker.log \
|
|
--output=/var/log/koha/$name/worker-output.log \
|
|
--pidfiles=/var/run/koha/$name/ \
|
|
--verbose=1 --respawn --delay=30 \
|
|
--user=$name-koha.$name-koha"
|
|
|
|
log_daemon_msg "Stopping Koha worker 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: worker not running for $name"
|
|
log_end_msg 1
|
|
fi
|
|
}
|
|
|
|
restart_worker()
|
|
{
|
|
local name=$1
|
|
|
|
if is_worker_running $name; then
|
|
export KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml"
|
|
|
|
DAEMONOPTS="--name=$name-koha-worker \
|
|
--errlog=/var/log/koha/$name/worker-error.log \
|
|
--stdout=/var/log/koha/$name/worker.log \
|
|
--output=/var/log/koha/$name/worker-output.log \
|
|
--pidfiles=/var/run/koha/$name/ \
|
|
--verbose=1 --respawn --delay=30 \
|
|
--user=$name-koha.$name-koha"
|
|
|
|
log_daemon_msg "Restarting Koha worker daemon for $name"
|
|
|
|
if daemon $DAEMONOPTS --restart -- $worker_DAEMON; then
|
|
log_end_msg 0
|
|
else
|
|
log_end_msg 1
|
|
fi
|
|
else
|
|
log_daemon_msg "Error: worker not running for $name"
|
|
log_end_msg 1
|
|
fi
|
|
}
|
|
|
|
worker_status()
|
|
{
|
|
local name=$1
|
|
|
|
if is_worker_running ${name}; then
|
|
log_daemon_msg "worker running for ${name}"
|
|
log_end_msg 0
|
|
else
|
|
log_daemon_msg "worker not running for ${name}"
|
|
log_end_msg 3
|
|
fi
|
|
}
|
|
|
|
set_action()
|
|
{
|
|
if [ "$op" = "" ]; then
|
|
op=$1
|
|
else
|
|
die "Error: only one action can be specified."
|
|
fi
|
|
}
|
|
|
|
op=""
|
|
quiet="no"
|
|
|
|
# Read command line parameters
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
-h|--help)
|
|
usage ; exit 0 ;;
|
|
-q|--quiet)
|
|
quiet="yes"
|
|
shift ;;
|
|
--start)
|
|
set_action "start"
|
|
shift ;;
|
|
--stop)
|
|
set_action "stop"
|
|
shift ;;
|
|
--restart)
|
|
set_action "restart"
|
|
shift ;;
|
|
--status)
|
|
set_action "status"
|
|
shift ;;
|
|
-*)
|
|
die "Error: invalid option switch ($1)" ;;
|
|
*)
|
|
# We expect the remaining stuff are the instance names
|
|
break ;;
|
|
esac
|
|
|
|
done
|
|
|
|
# Optionally use alternative paths for a dev install
|
|
adjust_paths_dev_install $1
|
|
|
|
if [ "$DEV_INSTALL" = "" ]; then
|
|
worker_DAEMON="${KOHA_HOME}/bin/background_jobs_worker.pl"
|
|
else
|
|
worker_DAEMON="${KOHA_HOME}/misc/background_jobs_worker.pl"
|
|
fi
|
|
|
|
# PERL5LIB has been read from etc/default
|
|
export PERL5LIB
|
|
|
|
if [ $# -gt 0 ]; then
|
|
# We have at least one instance name
|
|
for name in "$@"; do
|
|
|
|
if is_instance $name; then
|
|
|
|
case $op in
|
|
"start")
|
|
start_worker $name
|
|
;;
|
|
"stop")
|
|
stop_worker $name
|
|
;;
|
|
"restart")
|
|
restart_worker $name
|
|
;;
|
|
"status")
|
|
worker_status $name
|
|
esac
|
|
|
|
else
|
|
if [ "$quiet" = "no" ]; then
|
|
log_daemon_msg "Error: Invalid instance name $name"
|
|
log_end_msg 1
|
|
fi
|
|
fi
|
|
|
|
done
|
|
else
|
|
if [ "$quiet" = "no" ]; then
|
|
warn "Error: you must provide at least one instance name"
|
|
fi
|
|
fi
|
|
|
|
exit 0
|