From 98b134ddfe7c9991471ca6790f601a4c652350ad Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 31 May 2013 15:56:59 -0300 Subject: [PATCH] Bug 10733: Memcached on package installs This patch makes the koha-create script adjust the koha-conf.xml file with the proper string substitutions to enable the use of memcached for the created Koha instance. It adds three option switches that control this: --use-memcached (defaults to "no") --memcached-servers "host1:port1,..." (defaults to '127.0.0.1:11211') --memcached-prefix "desired_namespace prefix" (defaults to 'koha_') It respects the current schema configuration schema, where configuration values are pondered like this: hardcoded < koha-sites.conf < koha-create option switches koha-sites.conf is read for USE_MEMCACHED, MEMCACHED_SERVERS and MEMCACHED_PREFIX. Note: the docs discourage setting user's own namespace prefix. Using memcached is off as the default. The relevant configuration variables will remain empty if the user doesn't pass --use-memcached to the command. It matches the current behaviour. To test: - Apply the patch - Build your own packages and install them on a test server a) Create a new instance without using the new switches like: $ koha-create --create-db memctest - Check that /etc/koha/sites/memctest/koha-conf.xml contains: * Empty tag. * Empty tag. b) Play with the possible combination of option switches (Note that the code defaults to empty and will remain like that if --use-memcached is not used, so less tests...) $ koha-create --create-db --use-memcached memctest $ koha-create --create-db --use-memcached --memcached-servers "anything:xxx" memctest $ koha-create --create-db --use-memcached --memcached-servers "anything:xxx" --memcached-prefix "something" memctest $ koha-create --create-db --use-memcached --memcached-prefix "something" memctest - Check the koha-conf.xml and /etc/apache2/sites-enabled/memctest file reflect the chosen options. c) Run $ koha-create --help - It should advertise this addition accordingly. d) Run $ man koha-create - Man page for koha-create should provide good information on the new switches behaviour Enjoy To+ Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Mark Tompsett Signed-off-by: Robin Sheat --- debian/docs/koha-create.xml | 46 +++++++++++++ debian/scripts/koha-create | 114 +++++++++++++++++++++++++++------ debian/templates/apache-site.conf.in | 4 ++ debian/templates/koha-conf-site.xml.in | 4 +- 4 files changed, 148 insertions(+), 20 deletions(-) diff --git a/debian/docs/koha-create.xml b/debian/docs/koha-create.xml index 6ac2171..99ce191 100644 --- a/debian/docs/koha-create.xml +++ b/debian/docs/koha-create.xml @@ -29,6 +29,9 @@ en|es|fr|nb|ru|uk dom|grs1 dom|grs1 + + server:port + namespace_prefix /path/to/some.sql /path/to/config /path/to/passwd @@ -125,6 +128,27 @@ + + + + Make the Koha instance use memcached. . + + + + + + + Specify a comma-separated list of host:port memcached servers for using with the created Koha instance. Defaults to , the needed configuration for a locally installed memcached server. + + + + + + + Specifiy a for memcached. You usually leave this option alone to avoid namespace collisions. It defaults to . + + + @@ -195,6 +219,28 @@ + + + Valid values are and . If not present koha-create will default to . Also, this will be overriden by the switch. + + + + + + + A comma-separated list of valid memcached servers. Usually in the form of . If not present koha-create will default to . Also, this will be overriden by the arguments of the switch. + + + + + + + A prefix for all new Koha instances to use in memcached. If not present koha-create will default to . Also, this will be overriden by the arguments of the switch. + + + + + Specifies format of MARC records to be indexed by Zebra. Possible values are 'marc21', 'normarc' and 'unimarc'. diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index e8b2578..e09b5ba 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -23,6 +23,8 @@ usage="Usage: $0 [--create-db|--request-db|--populate-db|--use-db] \ [--marcflavor marc21|normarc|unimarc] \ [--zebralang en|es|fr|nb|ru|uk] \ [--auth-idx dom|grs1] [--biblio-idx dom|grs1] \ + [--use-memcached] \ + [--memcached-servers server:port] [--memcached-prefix prefix] \ [--defaultsql /path/to/some.sql] \ [--configfile /path/to/config] [--passwdfile /path/to/passwd] \ [--database database] [--adminuser n] instancename" @@ -61,6 +63,8 @@ generate_config_file() { -e "s/__UNIXUSER__/$username/g" \ -e "s/__UNIXGROUP__/$username/g" \ -e "s/__PLUGINS_DIR__/\/var\/lib\/koha\/$name\/plugins/g" \ + -e "s/__MEMCACHED_NAMESPACE__/$MEMCACHED_NAMESPACE/g" \ + -e "s/__MEMCACHED_SERVERS__/$MEMCACHED_SERVERS/g" \ "/etc/koha/$1" > "$2" } @@ -154,6 +158,32 @@ EOF` esac } + +set_memcached() +{ + local instance="$1" + + if [ "$CLO_MEMCACHED_SERVERS" != "" ]; then + MEMCACHED_SERVERS=$CLO_MEMCACHED_SERVERS + else + if [ "$MEMCACHED_SERVERS" = "" ]; then + MEMCACHED_SERVERS=$DEFAULT_MEMCACHED_SERVERS + # else: was set by the koha-sites.conf file + fi + fi + + if [ "$CLO_MEMCACHED_PREFIX" != "" ]; then + MEMCACHED_NAMESPACE="$CLO_MEMCACHED_PREFIX$instance" + else + if [ "$MEMCACHED_PREFIX" != "" ]; then + MEMCACHED_NAMESPACE="$MEMCACHED_PREFIX$instance" + else + MEMCACHED_NAMESPACE="$DEFAULT_MEMCACHED_PREFIX$instance" + fi + fi + +} + # Set defaults and read config file, if it exists. DOMAIN="" OPACPORT="80" @@ -168,6 +198,14 @@ ZEBRA_LANGUAGE="en" ADMINUSER="1" PASSWDFILE="/etc/koha/passwd" +# memcached variables +USE_MEMCACHED="no" +MEMCACHED_SERVERS="" +MEMCACHED_PREFIX="" +# hardcoded memcached defaults +DEFAULT_MEMCACHED_SERVERS="127.0.0.1:11211" +DEFAULT_MEMCACHED_PREFIX="koha_" + # Indexing mode variables (default is DOM) BIBLIOS_INDEXING_MODE="dom" AUTHORITIES_INDEXING_MODE="dom" @@ -184,7 +222,7 @@ fi [ $# -ge 2 ] && [ $# -le 16 ] || die $usage -TEMP=`getopt -o crpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,database:,adminuser: \ +TEMP=`getopt -o crpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,use-memcached,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,database:,adminuser:,memcached-servers:,memcached-prefix:, \ -n "$0" -- "$@"` # Note the quotes around `$TEMP': they are essential! @@ -197,26 +235,49 @@ CLO_DEFAULTSQL="" CLO_ADMINUSER="" CLO_BIBLIOS_INDEXING_MODE="" CLO_AUTHORITIES_INDEXING_MODE="" +CLO_MEMCACHED_SERVERS="" +CLO_MEMCACHED_PREFIX="" while true ; do - case "$1" in - -c|--create-db) op=create ; shift ;; - -r|--request-db) op=request ; shift ;; - -p|--populate-db) op=populate ; shift ;; - -u|--use-db) op=use ; shift ;; - -m|--marcflavor) CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;; - -l|--zebralang) CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; - --auth-idx) CLO_AUTHORITIES_INDEXING_MODE="$2" ; shift 2 ;; - --biblio-idx) CLO_BIBLIOS_INDEXING_MODE="$2" ; shift 2 ;; - -d|--defaultsql) CLO_DEFAULTSQL="$2" ; shift 2 ;; - -f|--configfile) configfile="$2" ; shift 2 ;; - -s|--passwdfile) CLO_PASSWDFILE="$2" ; shift 2 ;; - -b|--database) CLO_DATABASE="$2" ; shift 2 ;; - -a|--adminuser) CLO_ADMINUSER="$2" ; shift 2 ;; - --) shift ; break ;; - *) die "Internal error processing command line arguments" ;; - esac + case "$1" in + -c|--create-db) + op=create ; shift ;; + -r|--request-db) + op=request ; shift ;; + -p|--populate-db) + op=populate ; shift ;; + -u|--use-db) + op=use ; shift ;; + --use-memcached) + USE_MEMCACHED="yes" ; shift ;; + --memcached-servers) + CLO_MEMCACHED_SERVERS="$2" ; shift 2 ;; + --memcached-prefix) + CLO_MEMCACHED_PREFIX="$2" ; shift 2;; + -m|--marcflavor) + CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;; + -l|--zebralang) + CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; + --auth-idx) + CLO_AUTHORITIES_INDEXING_MODE="$2" ; shift 2 ;; + --biblio-idx) + CLO_BIBLIOS_INDEXING_MODE="$2" ; shift 2 ;; + -d|--defaultsql) + CLO_DEFAULTSQL="$2" ; shift 2 ;; + -f|--configfile) + configfile="$2" ; shift 2 ;; + -s|--passwdfile) + CLO_PASSWDFILE="$2" ; shift 2 ;; + -b|--database) + CLO_DATABASE="$2" ; shift 2 ;; + -a|--adminuser) + CLO_ADMINUSER="$2" ; shift 2 ;; + --) + shift ; break ;; + *) + die "Internal error processing command line arguments" ;; + esac done # Load the configfile given on the command line @@ -267,6 +328,23 @@ set_authorities_indexing_mode $AUTHORITIES_INDEXING_MODE $ZEBRA_MARC_FORMAT name="$1" +if [ "$USE_MEMCACHED" = "yes" ]; then + set_memcached $name +elif [ "$CLO_MEMCACHED_SERVERS" != "" ] || \ + [ "$CLO_MEMCACHED_PREFIX" != "" ]; then + + MSG=`cat <http://__PAZPAR2_HOST__:__PAZPAR2_PORT__/search.pz2 --> /usr/share/koha/misc/koha-install-log 0 - - + __MEMCACHED_SERVERS__ + __MEMCACHED_NAMESPACE__ __BIBLIOS_INDEXING_MODE__ __AUTHORITIES_INDEXING_MODE__ /etc/koha/searchengine/queryparser.yaml -- 1.8.1.2