Bugzilla – Attachment 84521 Details for
Bug 18562
Add koha-sip script to handle SIP servers for instances
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18562: Add koha-sip maintenance script
Bug-18562-Add-koha-sip-maintenance-script.patch (text/plain), 10.86 KB, created by
Kyle M Hall (khall)
on 2019-01-30 13:19:09 UTC
(
hide
)
Description:
Bug 18562: Add koha-sip maintenance script
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2019-01-30 13:19:09 UTC
Size:
10.86 KB
patch
obsolete
>From d5187298cb5330f7933aff4657cac610221ade42 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 30 Jan 2019 08:42:53 -0300 >Subject: [PATCH] Bug 18562: Add koha-sip maintenance script > >This patch introduces a single script to handle all actions on SIP >servers for Koha instances. It is intended to be a replacement for: > >- koha-start-sip >- koha-stop-sip >- koha-enable-sip > >It adds a function called is_sip_running to koha-functions.sh. > >To test: >- Apply this patch >- Run: > $ misc4dev/cp_debian_files.pl > $ sudo koha-sip --enable kohadev > $ sudo koha-sip --start kohadev > $ sudo koha-sip --status kohadev >=> SUCCESS: The SIP server is running for kohadev >- Run: > $ sudo koha-sip --restart --verbose kohadev > $ sudo koha-sip --status kohadev >=> SUCCESS: The SIP server is running for kohadev >- Run: > $ sudo koha-sip --stop kohadev > $ sudo koha-sip --status kohadev >=> SUCCESS: The SIP server is not running for kohadev >- Play with other combinations like enabling an already enabled >instance, etc. Remember you need to remove the >/etc/koha/sites/kohadev/SIPconfig.xml file so it is considered disabled. >- Sign off :-D > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > debian/koha-common.install | 1 + > debian/scripts/koha-functions.sh | 14 ++ > debian/scripts/koha-sip | 308 +++++++++++++++++++++++++++++++ > 3 files changed, 323 insertions(+) > create mode 100755 debian/scripts/koha-sip > >diff --git a/debian/koha-common.install b/debian/koha-common.install >index f31bfdef8e..6c54fc28fa 100644 >--- a/debian/koha-common.install >+++ b/debian/koha-common.install >@@ -37,4 +37,5 @@ debian/scripts/koha-zebra usr/sbin > debian/scripts/koha-start-sip usr/sbin > debian/scripts/koha-stop-sip usr/sbin > debian/scripts/koha-enable-sip usr/sbin >+debian/scripts/koha-sip usr/sbin > debian/tmp_docbook/*.8 usr/share/man/man8 >diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh >index c6f79b4933..3a04db7851 100755 >--- a/debian/scripts/koha-functions.sh >+++ b/debian/scripts/koha-functions.sh >@@ -157,6 +157,20 @@ is_sitemap_enabled() > fi > } > >+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 >+ fi >+} >+ > is_zebra_running() > { > local instancename=$1 >diff --git a/debian/scripts/koha-sip b/debian/scripts/koha-sip >new file mode 100755 >index 0000000000..da6909ba43 >--- /dev/null >+++ b/debian/scripts/koha-sip >@@ -0,0 +1,308 @@ >+#!/bin/bash >+ >+# koha-sip - Manage SIP server for Koha instances >+# Copyright 2019 Theke Solutions >+# Copyright 2012 Catalyst IT, Ltd >+# >+# 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 SIP server for your Koha instances. >+ >+Usage: >+$scriptname [--start|--stop|--restart] instancename1 [instancename2...] >+$scriptname -h|--help >+ >+ --start Start the SIP server for the specified instance(s) >+ --stop Stop the SIP server for the specified instance(s) >+ --restart Restart the SIP server for the specified instance(s) >+ --status Show the status of the SIP server for the specified instance(s) >+ --verbose|-v Display progress and actions messages >+ --help|-h Display this help message >+ >+EOF >+} >+ >+start_sip() >+{ >+ local name=$1 >+ >+ _check_and_fix_perms $name >+ >+ if ! is_sip_running $name; then >+ >+ adjust_paths_dev_install $name >+ export KOHA_CONF PERL5LIB >+ if [ "$DEV_INSTALL" = "" ]; then >+ LIBDIR=$KOHA_HOME/lib >+ else >+ LIBDIR=$KOHA_HOME >+ fi >+ >+ DAEMONOPTS="--name=${name}-koha-sip \ >+ --errlog=/var/log/koha/${name}/sip-error.log \ >+ --stdout=/var/log/koha/${name}/sip.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 Koha Zebra daemon 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 >+ else >+ if [ "$verbose" != "no" ]; then >+ log_daemon_msg "Warning: SIP server already running for ${name}" >+ log_end_msg 0 >+ else >+ return 0 >+ fi >+ fi >+} >+ >+stop_sip() >+{ >+ local name=$1 >+ >+ if is_sip_running $name; then >+ >+ DAEMONOPTS="--name=${name}-koha-sip \ >+ --errlog=/var/log/koha/${name}/sip-error.log \ >+ --stdout=/var/log/koha/${name}/sip.log \ >+ --output=/var/log/koha/${name}/sip-output.log \ >+ --verbose=1 \ >+ --respawn \ >+ --delay=30 \ >+ --pidfiles=/var/run/koha/${name} \ >+ --user=${name}-koha.${name}-koha" >+ >+ [ "$verbose" != "no" ] && \ >+ log_daemon_msg "Stopping SIP server for ${name}" >+ >+ if daemon $DAEMONOPTS --stop; 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 >+} >+ >+restart_sip() >+{ >+ local name=$1 >+ >+ if is_sip_running ${name}; then >+ local noLF="-n" >+ [ "$verbose" != "no" ] && noLF="" >+ echo $noLF `stop_sip ${name}` >+ echo $noLF `start_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 >+ fi >+} >+ >+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 >+} >+ >+enable_sip() >+{ >+ local name=$1 >+ >+ sipfile=/etc/koha/sites/${name}/SIPconfig.xml >+ >+ if is_sip_enabled ${name}; then >+ echo "Warning: SIP server already enabled for ${name}" >+ else >+ echo "Enabling SIP server for ${name} - edit ${sipfile} to configure" >+ cp -v /etc/koha/SIPconfig.xml ${sipfile} >+ chown ${name}-koha:${name}-koha ${sipfile} >+ chmod 600 ${sipfile} >+ fi >+} >+ >+_check_and_fix_perms() >+{ >+ local name=$1 >+ >+ local files="/var/log/koha/${name}/sip-error.log \ >+ /var/log/koha/${name}/sip.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 >+ op=$1 >+ else >+ die "Error: only one action can be specified." >+ fi >+} >+ >+op="" >+verbose="no" >+ >+# Backwards compatible with old koha-*-sip scripts >+# TODO: Remove once there's consensus to remove the legacy scripts >+used_script_name=$(basename $0) >+ >+if [ "$used_script_name" != "koha-sip" ]; then >+ warn "Deprecated script used (${used_script_name})" >+ >+ case "$used_script_name" in >+ koha-start-sip) >+ set_action "start" ;; >+ koha-stop-sip) >+ set_action "stop" ;; >+ *) >+ break ;; >+ esac >+fi >+# / Backwards compatible handling code >+ >+# Read command line parameters >+while [ $# -gt 0 ]; do >+ >+ case "$1" in >+ -h|--help) >+ usage ; exit 0 ;; >+ -v|--verbose) >+ verbose="yes" >+ shift ;; >+ --start) >+ set_action "start" >+ shift ;; >+ --stop) >+ set_action "stop" >+ shift ;; >+ --restart) >+ set_action "restart" >+ shift ;; >+ --status) >+ set_action "status" >+ shift ;; >+ --enable) >+ set_action "enable" >+ shift ;; >+ -*) >+ die "Error: invalid option switch ($1)" ;; >+ *) >+ # We expect the remaining stuff are the instance names >+ break ;; >+ esac >+ >+done >+ >+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_sip $name >+ ;; >+ "stop") >+ stop_sip $name >+ ;; >+ "restart") >+ restart_sip $name >+ ;; >+ "status") >+ sip_status $name >+ ;; >+ "enable") >+ enable_sip $name >+ esac >+ >+ else >+ if [ "$verbose" != "no" ]; then >+ log_daemon_msg "Error: Invalid instance name $name" >+ log_end_msg 1 >+ fi >+ fi >+ >+ done >+else >+ if [ "$verbose" != "no" ]; then >+ warn "Error: you must provide at least one instance name" >+ fi >+fi >+ >+exit 0 >-- >2.17.2 (Apple Git-113)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18562
:
84511
|
84512
|
84513
|
84521
|
84522
|
84523
|
84951
|
84952
|
84953