From 39d3b9088a34b464708e40d1fd20a954d4a6e702 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 30 Apr 2013 11:58:25 -0300 Subject: [PATCH 1/4] Bug 10159 - koha-rebuild-zebra error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch makes koha-rebuild-zebra: - Check for the existence of the instance - Handle arbitrary amount of instance parameters - Capture -a and -b (which made the script rebuild twice the chosen DB). It adds the extended version (--authorities and --biblios respectively) of the option switch. This makes the -a and -b switches work as "only do authorities" (or viceversa). They can be used concurrently, which is the default behaviour when no switch is provided. - Handle -v (and --verbose) as koha-rebuild-zebra options, to ease the use for non-techie users. - The rebuild_zebra.pl is wrapped inside an IF to return error values if we ever make rebuild_zebra.pl return error codes (this is pointed in the code). - Added -h/--help switches and an 'usage' output :-D Please provide patches for any wording issues, or contact me to fix it. To test: - Apply the patch and create your packages (or just use the script from your branch) - Run it in this scenarios / options - -h/--help to see the available option switches - Mix them with one or more instances, of which some could be fake - try -a/--authorities and -b/--biblios in all possible combinations - try -v/--verbose works Regards To+ Sponsored-by: Universidad Nacional de Córdoba Signed-off-by: Robin Sheat Signed-off-by: Jared Camins-Esakov --- debian/docs/koha-rebuild-zebra.xml | 26 +++++- debian/scripts/koha-rebuild-zebra | 143 +++++++++++++++++++++++++---- 2 files changed, 147 insertions(+), 22 deletions(-) diff --git a/debian/docs/koha-rebuild-zebra.xml b/debian/docs/koha-rebuild-zebra.xml index b8ce51cac3..410be8abad 100644 --- a/debian/docs/koha-rebuild-zebra.xml +++ b/debian/docs/koha-rebuild-zebra.xml @@ -17,13 +17,13 @@ koha-rebuild-zebra - Rebuild the Zebra database for a Koha instance. + Rebuild the Zebra database for Koha instances. UNIX/Linux - koha-rebuild-zebra | | instancename + koha-rebuild-zebra | | | | | instancename @@ -41,17 +41,35 @@ Does a reindex of the whole collection. + + + + Only run the indexing process for authority records. + + + + + + Only run the indexing process for biblio records. + + + + + + Be verbose. Useful for debugging indexing problems. + + - Anything else is passed directly to rebuild_zebra. This is useful in particular for -v. + Anything else is passed directly to rebuild_zebra. Description - Rebuild the Zebra database for a Koha instance. + Rebuild the Zebra database for Koha instances. See also diff --git a/debian/scripts/koha-rebuild-zebra b/debian/scripts/koha-rebuild-zebra index b4478fd5d2..f32ca8bbdb 100755 --- a/debian/scripts/koha-rebuild-zebra +++ b/debian/scripts/koha-rebuild-zebra @@ -1,6 +1,6 @@ #!/bin/sh # -# koha-rebuild-zebra -- Rebuild the Zebra database for a Koha instance. +# koha-rebuild-zebra - Rebuild the Zebra database for Koha instances. # Copyright 2010 Catalyst IT, Ltd # # This program is free software: you can redistribute it and/or modify @@ -19,18 +19,117 @@ set -e +die() +{ + echo "$@" 1>&2 + exit 1 +} + +warn() +{ + echo "$@" 1>&2 +} + +is_instance() +{ + local instancename=$1 + + if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ + -type d -printf '%f\n'\ + | grep -q -x $instancename ; then + return 0 + else + return 1 + fi +} + +toggle_biblios_only() +{ + biblios_only="yes" + biblios="yes" + if [ "$authorities_only" != "yes" ]; then + authorities="no" + fi +} + +toggle_authorities_only() +{ + authorities_only="yes" + authorities="yes" + if [ "$biblios_only" != "yes" ]; then + biblios="no" + fi +} + +run_rebuild_zebra() +{ + local instancename=$1; shift + + # TODO: This comment is here to remind us that we should make + # rebuild_zebra.pl return error codes on failure + if sudo -u "$instancename-koha" -H \ + env PERL5LIB=/usr/share/koha/lib \ + KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \ + /usr/share/koha/bin/migration_tools/rebuild_zebra.pl $@ ; then + return 0 + else + return 1 + fi +} + +usage() +{ + local scriptname=$0 + cat < Date: Tue, 30 Apr 2013 10:05:44 -0300 Subject: [PATCH 2/4] Bug 10157 - koha-email-enable error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit koha-email-enable now - Checks the instance exists. - Checks if email is already enabled. Regards To+ Sponsored-by: Universidad Nacional de Córdoba Signed-off-by: Robin Sheat Signed-off-by: Jared Camins-Esakov --- debian/docs/koha-email-enable.xml | 4 +- debian/scripts/koha-email-enable | 81 ++++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/debian/docs/koha-email-enable.xml b/debian/docs/koha-email-enable.xml index 0f39010bff..1aeb2f1551 100644 --- a/debian/docs/koha-email-enable.xml +++ b/debian/docs/koha-email-enable.xml @@ -17,7 +17,7 @@ koha-email-enable - Turn on the email for a Koha instance. + Turn on the email for Koha instances. UNIX/Linux @@ -28,7 +28,7 @@ Description - Turn on the email for a Koha instance. + Turn on the email for Koha instances. See also diff --git a/debian/scripts/koha-email-enable b/debian/scripts/koha-email-enable index da63589ea0..a130c49983 100755 --- a/debian/scripts/koha-email-enable +++ b/debian/scripts/koha-email-enable @@ -1,6 +1,6 @@ #!/bin/sh # -# koha-email-enable -- turn on the email for a Koha instance +# koha-email-enable - turn on the email for Koha instances # Copyright 2010 Catalyst IT, Ltd # # This program is free software: you can redistribute it and/or modify @@ -18,19 +18,76 @@ set -e -if [ "$#" = 0 ] -then - echo "Enables email for a koha instance." 1>&2 - echo "Usage: $0 instancename..." 1>&2 +die() +{ + echo "$@" 1>&2 exit 1 -fi -libdir=/var/lib/koha +} + +warn() +{ + echo "$@" 1>&2 +} + +is_instance() +{ + local instancename=$1 + + if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ + -type d -printf '%f\n'\ + | grep -q -x $instancename ; then + return 0 + else + return 1 + fi +} + +is_email_enabled() +{ + local instancename=$1 + + if [ -e /var/lib/koha/$instancename/email.enabled ]; then + return 0 + else + return 1 + fi +} + +enable_email() +{ + local instancename=$1 + local libdir="/var/lib/koha" + + touch $libdir/$instancename/email.enabled + + echo "Enabled email for instance $instancename." +} + +usage() +{ + local scriptname=$0 + cat <&2 - continue + if is_instance $name; then + if ! is_email_enabled $name; then + enable_email $name + else + warn "Email already enabled for instance $name." + fi + else + warn "Unknown instance $name." fi - touch $libdir/$name/email.enabled done + +exit 0 From 898e178c6ff3a79bf991defb60aec8ff58f107c6 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 29 Apr 2013 11:08:35 -0300 Subject: [PATCH 3/4] Bug 10146 - koha-stop-zebra error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit koha-stop-zebra now - Checks the instance exists. - Checks the instance is enabled. - Checks if the zebra daemon is already running. Regards To+ Edit: Corrected the die message Sponsored-by: Universidad Nacional de Córdoba Signed-off-by: Robin Sheat Signed-off-by: Jared Camins-Esakov --- debian/scripts/koha-stop-zebra | 127 +++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 15 deletions(-) diff --git a/debian/scripts/koha-stop-zebra b/debian/scripts/koha-stop-zebra index 7f3efcc0ce..ae15cc7f51 100755 --- a/debian/scripts/koha-stop-zebra +++ b/debian/scripts/koha-stop-zebra @@ -1,6 +1,6 @@ #!/bin/sh # -# koha-stop-zebra -- Stop Zebra for named Koha instandes +# koha-stop-zebra - Stop Zebra for named Koha instances # Copyright 2010 Catalyst IT, Ltd # # This program is free software: you can redistribute it and/or modify @@ -18,20 +18,117 @@ set -e +die() +{ + echo "$@" 1>&2 + exit 1 +} + +warn() +{ + echo "$@" 1>&2 +} + +is_enabled() +{ + local instancename=$1 + + if ! is_instance $instancename; then + return 1 + fi + + if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ + "/etc/apache2/sites-available/$instancename" ; then + return 1 + else + return 0 + fi +} + +is_instance() +{ + local instancename=$1 + + if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ + -type d -printf '%f\n'\ + | grep -q -x $instancename ; then + return 0 + else + return 1 + fi +} + +is_zebra_running() +{ + local instancename=$1 + + if daemon --name="$instancename-koha-zebra" \ + --user="$instancename-koha.$instancename-koha" \ + --running ; then + return 0 + else + return 1 + fi +} + +stop_zebra_instance() +{ + local instancename=$1 + + if is_zebra_running $instancename; then + echo "Stopping Zebra server for $instancename" + daemon \ + --name="$instancename-koha-zebra" \ + --errlog="/var/log/koha/$instancename/zebra-error.log" \ + --stdout="/var/log/koha/$instancename/zebra.log" \ + --output="/var/log/koha/$instancename/zebra-output.log" \ + --verbose=1 \ + --respawn \ + --delay=30 \ + --user="$instancename-koha.$instancename-koha" \ + --stop \ + -- \ + zebrasrv \ + -v none,fatal,warn \ + -f "/etc/koha/sites/$instancename/koha-conf.xml" && \ + return 0 + else + return 1 + fi +} + +usage() +{ + local scriptname=$0 + cat < Date: Tue, 23 Apr 2013 10:14:37 -0300 Subject: [PATCH 4/4] Bug 10094 - koha-list should have a --disabled option switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds that (--disabled) option switch, Also revisits some of the code and docs. To test: - Apply the patch and create new packages (you might just drop the koha-list command somewhere) - Create several instances (koha-create) - Randomly set some as disabled, others enabled and enable email on some. - Test all possible option switches combinations Expected results: - koha-list should abort with a proper message if mutually exclusive options selected (--email vs. --noemail, --enabled vs. --disabled) - koha-list should show the exact instances you asked for Regards To+ P.S.: I wanted to add the --disabled option switch for the tab-completion work I'm doing, but as of bug 4876 I thought it would be ok to revisit the script to make it robust and clear. Sponsored-by: Universidad Nacional de Córdoba Signed-off-by: Robin Sheat Does what it says, and cleans up the script at the same time. Signed-off-by: Jared Camins-Esakov --- debian/docs/koha-list.xml | 10 ++- debian/scripts/koha-list | 134 +++++++++++++++++++++++++++++++------- 2 files changed, 119 insertions(+), 25 deletions(-) diff --git a/debian/docs/koha-list.xml b/debian/docs/koha-list.xml index c67096d0ad..b58847e3c1 100644 --- a/debian/docs/koha-list.xml +++ b/debian/docs/koha-list.xml @@ -23,12 +23,12 @@ - koha-list + koha-list | | Options - The filtering options can be combined, and you probably want to do this (except --email and --noemail, that's just silly.) + The filtering options can be combined, and you probably want to do this (except --email and --noemail, or --enabled and --disabled, that's just silly.) @@ -36,6 +36,12 @@ Only show instances that are enabled. + + + + Only show instances that are disabled. + + diff --git a/debian/scripts/koha-list b/debian/scripts/koha-list index 1e19f1afc4..f722cf10e4 100755 --- a/debian/scripts/koha-list +++ b/debian/scripts/koha-list @@ -1,6 +1,6 @@ #!/bin/sh # -# koha-instances -- List all Koha instances. +# koha-list -- List all Koha instances. # Copyright 2010 Catalyst IT, Ltd # # This program is free software: you can redistribute it and/or modify @@ -19,9 +19,18 @@ set -e -is_enabled() { +die() +{ + echo "$@" 1>&2 + exit 1 +} + +is_enabled() +{ + local instancename=$1 + if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ - "/etc/apache2/sites-available/$name" > /dev/null + "/etc/apache2/sites-available/$instancename" > /dev/null then return 1 else @@ -29,46 +38,125 @@ is_enabled() { fi } -help() { +is_email_enabled() +{ + local instancename=$1 + + if [ -e /var/lib/koha/$instancename/email.enabled ]; then + return 0 + else + return 1 + fi +} + +get_instances() +{ + find /etc/koha/sites -mindepth 1 -maxdepth 1\ + -type d -printf '%f\n' | sort +} + +show_instances() +{ + local show=$1 + local show_email=$2 + + for instance in $( get_instances ); do + case $show in + "all") + show_instance_filter_email $instance $show_email;; + "enabled") + if is_enabled $instance; then + show_instance_filter_email $instance $show_email + fi ;; + "disabled") + if ! is_enabled $instance; then + show_instance_filter_email $instance $show_email + fi ;; + esac + done +} + +show_instance_filter_email() +{ + local instancename=$1 + local show_email=$2; + + case $show_email in + "all") + echo $instancename ;; + "enabled") + if is_email_enabled $instancename; then + echo $instancename + fi ;; + "disabled") + if ! is_email_enabled $instancename; then + echo $instancename + fi ;; + esac +} + +set_show() +{ + local show_param=$1 + + if [ "$show" = "all" ]; then + show=$show_param + else + die "Error: --enabled and --disabled are mutually exclusive." + fi +} + +set_show_email() +{ + local email_param=$1 + + if [ "$show_email" = "all" ]; then + show_email=$email_param + else + die "Error: --email and --noemail are mutually exclusive." + fi +} + +usage() +{ + local scriptname=$0 + echo <