[Koha-patches] [PATCH 1/2] Bug 10733: Memcached on package installs

Tomas Cohen Arazi tomascohen at gmail.com
Thu Aug 15 00:30:46 CEST 2013


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 <memcached_servers> tag.
   * Empty <memcached_namespace> 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 @@
       <arg><option>--zebralang</option> en|es|fr|nb|ru|uk</arg>
       <arg><option>--auth-idx</option> dom|grs1</arg>
       <arg><option>--biblio-idx</option> dom|grs1</arg>
+      <arg><option>--use-memcached</option></arg>
+      <arg><option>--memcached-servers</option> server:port</arg>
+      <arg><option>--memcached-namespace</option> koha_namespace</arg>
       <arg><option>--defaultsql</option> /path/to/some.sql</arg>
       <arg><option>--configfile</option> /path/to/config</arg>
       <arg><option>--passwdfile</option> /path/to/passwd</arg>
@@ -125,6 +128,27 @@
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <term><option>--use-memcached</option></term>
+      <listitem>
+        <para>Make the Koha instance use memcached. <option>Disabled by default</option>.</para>
+      </listitem>
+    </varlistentry>
+
+    <varlistentry>
+      <term><option>--memcached-servers</option></term>
+      <listitem>
+        <para>Specify a comma-separated list of host:port memcached servers for using with the created Koha instance. Defaults to <option>127.0.0.1:11211</option>, the needed configuration for a locally installed memcached server.</para>
+      </listitem>
+    </varlistentry>
+
+    <varlistentry>
+      <term><option>--memcached-namespace</option></term>
+      <listitem>
+        <para>Specifiy a memcached <option>namespace</option> for the created Koha instance. You usually leave this option alone to avoid namespace collisions. It defaults to <option>koha_instance</option>.</para>
+      </listitem>
+    </varlistentry>
+
   </variablelist>
   </refsect1>
 
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 @@
  <!-- <pazpar2url>http://__PAZPAR2_HOST__:__PAZPAR2_PORT__/search.pz2</pazpar2url> -->
  <install_log>/usr/share/koha/misc/koha-install-log</install_log>
  <useldapserver>0</useldapserver><!-- see C4::Auth_with_ldap for extra configs you must add if you want to turn this on -->
- <memcached_servers></memcached_servers>
- <memcached_namespace></memcached_namespace>
+ <memcached_servers>__MEMCACHED_SERVERS__</memcached_servers>
+ <memcached_namespace>__MEMCACHED_NAMESPACE__</memcached_namespace>
  <zebra_bib_index_mode>__BIBLIOS_INDEXING_MODE__</zebra_bib_index_mode>
  <zebra_auth_index_mode>__AUTHORITIES_INDEXING_MODE__</zebra_auth_index_mode>
  <queryparser_config>/etc/koha/searchengine/queryparser.yaml</queryparser_config>
-- 
1.8.1.2



More information about the Koha-patches mailing list