From d51a3818810d075ee6978dc00f4231dfab46bfc7 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-namespace "desired_namespace" (defaults to koha_${instance}) Note: the docs discourage setting user's own namespace. 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-namespace "something" memctest $ koha-create --create-db --use-memcached --memcached-namespace "something" memctest - Check the koha-conf.xml file reflects 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 --- debian/docs/koha-create.xml | 24 ++++++++++++++++++ debian/scripts/koha-create | 45 ++++++++++++++++++++++++++++++++-- debian/templates/koha-conf-site.xml.in | 4 +-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/debian/docs/koha-create.xml b/debian/docs/koha-create.xml index 31c168a..0781fd3 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 + koha_namespace /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 memcached for the created Koha instance. You usually leave this option alone to avoid namespace collisions. It defaults to . + + + diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index e8b2578..bcfadc9 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -61,6 +61,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 +156,26 @@ EOF` esac } + +set_memcached() +{ + local instance="$1" + + if [ "$CLO_MEMCACHED_SERVERS" != "" ]; then + MEMCACHED_SERVERS=$CLO_MEMCACHED_SERVERS + else + MEMCACHED_SERVERS=$DEFAULT_MEMCACHED_SERVERS + fi + + if [ "$CLO_MEMCACHED_NAMESPACE" != "" ]; then + MEMCACHED_NAMESPACE=$CLO_MEMCACHED_NAMESPACE + else + # default + MEMCACHED_NAMESPACE="koha_$instance" + fi + +} + # Set defaults and read config file, if it exists. DOMAIN="" OPACPORT="80" @@ -167,6 +189,10 @@ ZEBRA_MARC_FORMAT="marc21" ZEBRA_LANGUAGE="en" ADMINUSER="1" PASSWDFILE="/etc/koha/passwd" +USE_MEMCACHED="no" +MEMCACHED_SERVERS="" +MEMCACHED_NAMESPACE="" +DEFAULT_MEMCACHED_SERVERS="127.0.0.1:11211" # Indexing mode variables (default is DOM) BIBLIOS_INDEXING_MODE="dom" @@ -184,7 +210,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-namespace:, \ -n "$0" -- "$@"` # Note the quotes around `$TEMP': they are essential! @@ -197,6 +223,8 @@ CLO_DEFAULTSQL="" CLO_ADMINUSER="" CLO_BIBLIOS_INDEXING_MODE="" CLO_AUTHORITIES_INDEXING_MODE="" +CLO_MEMCACHED_SERVERS="" +CLO_MEMCACHED_NAMESPACE="" while true ; do @@ -204,7 +232,16 @@ while true ; do -c|--create-db) op=create ; shift ;; -r|--request-db) op=request ; shift ;; -p|--populate-db) op=populate ; shift ;; - -u|--use-db) op=use ; shift ;; + -u|--use-db) op=use ; shift ;; + --use-memcached) + USE_MEMCACHED="yes" + shift ;; + --memcached-servers) + CLO_MEMCACHED_SERVERS="$2" + shift 2 ;; + --memcached-namespace) + CLO_MEMCACHED_NAMESPACE="$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 ;; @@ -267,6 +304,10 @@ set_authorities_indexing_mode $AUTHORITIES_INDEXING_MODE $ZEBRA_MARC_FORMAT name="$1" +if [ "$USE_MEMCACHED" = "yes" ]; then + set_memcached $name +fi + opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN" intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN" diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in index 71de9fb..9bf090b 100644 --- a/debian/templates/koha-conf-site.xml.in +++ b/debian/templates/koha-conf-site.xml.in @@ -276,8 +276,8 @@ /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