[Koha-patches] [PATCH] Bug 10733: Memcached on package installs
Tomas Cohen Arazi
tomascohen at gmail.com
Thu Sep 12 20:18:04 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-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 <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-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
---
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 @@
<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-prefix</option> namespace_prefix</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-prefix</option></term>
+ <listitem>
+ <para>Specifiy a <option>namespace prefix</option> for memcached. You usually leave this option alone to avoid namespace collisions. It defaults to <option>koha_</option>.</para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
@@ -195,6 +219,28 @@
</varlistentry>
<varlistentry>
+ <term><option>USE_MEMCACHED</option></term>
+ <listitem>
+ <para>Valid values are <option>yes</option> and <option>no</option>. If not present koha-create will default to <option>no</option>. Also, this will be overriden by the <option>--use-memcached</option> switch.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>MEMCACHED_SERVERS</option></term>
+ <listitem>
+ <para>A comma-separated list of valid memcached servers. Usually in the form of <option>host:port</option>. If not present koha-create will default to <option>127.0.0.1:11211</option>. Also, this will be overriden by the arguments of the <option>--memcached-servers</option> switch.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>MEMCACHED_PREFIX</option></term>
+ <listitem>
+ <para>A prefix for all new Koha instances to use in memcached. If not present koha-create will default to <option>koha_</option>. Also, this will be overriden by the arguments of the <option>--memcached-prefix</option> switch.</para>
+ </listitem>
+ </varlistentry>
+
+
+ <varlistentry>
<term><option>ZEBRA_MARC_FORMAT</option></term>
<listitem>
<para>Specifies format of MARC records to be indexed by Zebra. Possible values are 'marc21', 'normarc' and 'unimarc'.</para>
diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create
index e8b2578..491a218 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 <<EOF
+
+Error: you provided memcached configuration switches but memcached is not enabled.
+Please set USE_MEMCACHED="yes" on /etc/koha/koha-sites.conf or use the
+--use-memcached optio switch to enable it.
+
+EOF`
+
+ echo $usage
+ die $MSG
+fi
+
opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN"
intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN"
diff --git a/debian/templates/apache-site.conf.in b/debian/templates/apache-site.conf.in
index 42bdbcd..dd30bc6 100644
--- a/debian/templates/apache-site.conf.in
+++ b/debian/templates/apache-site.conf.in
@@ -8,6 +8,8 @@
ServerName __OPACSERVER__
SetEnv KOHA_CONF "/etc/koha/sites/__KOHASITE__/koha-conf.xml"
+ SetEnv MEMCACHED_SERVERS "__MEMCACHED_SERVERS__"
+ SetEnv MEMCACHED_NAMESPACE "__MEMCACHED_NAMESPACE__"
AssignUserID __UNIXUSER__ __UNIXGROUP__
ErrorLog /var/log/koha/__KOHASITE__/opac-error.log
@@ -23,6 +25,8 @@
ServerName __INTRASERVER__
SetEnv KOHA_CONF "/etc/koha/sites/__KOHASITE__/koha-conf.xml"
+ SetEnv MEMCACHED_SERVERS "__MEMCACHED_SERVERS__"
+ SetEnv MEMCACHED_NAMESPACE "__MEMCACHED_NAMESPACE__"
AssignUserID __UNIXUSER__ __UNIXGROUP__
ErrorLog /var/log/koha/__KOHASITE__/intranet-error.log
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.3.2
More information about the Koha-patches
mailing list