Bug 11404: add support for Apache 2.4's config file convention

Apache 2.4 expects the sites definition files use the sufix '.conf'

To reproduce:
- Install the 'koha-common' package on Debian 7 or Ubuntu 13.10+
  (both known to include Apache 2.4).
- Create an instance (for example testlibrary) using the supplied
  commands:
 $ koha-create --create-db testlibrary
> FAIL: apache reports an error like this:
"ERROR: Site testlibrary does not exist!"

This patch adds a test on the Apache version and appends the ".conf"
sufix if needed.

To test:

1st step: koha-create gets fixed:

-- The hard way --
- Apply the patch, and build the koha-common package on top of this
  commit.
- Install the built package on an Apache 2.4 Debian-based distro (Debian 7
  or Ubuntu 13.10 will work)
- Create a test instance:
 $ koha-create --create-db testlibrary
> SUCCESS: no more apache sites related error.

-- The easy way --
- Apply the patch, and copy the koha-create into an Apache 2.4
  Debian-based distro
- Create a test instance using the koha-create script you just
  copied:
 $ ./koha-create --create-db testlibrary
> SUCCESS: no more apache sites related error.

2nd step: the rest of the touched scripts keep working as usual

koha-disable
koha-dump
koha-enable
koha-list
koha-remove
koha-restart-zebra
koha-stop-zebra
koha-start-zebra

They should all keep working. Can be tested "the easy way" too.

Note: there might be another issues regarding Apache 2.4 deployments
like the need for

 $ a2enmod access_compat

and perhaps some directory permissions tweak, which I think should be
properly documented on the install instructions.

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Robin Sheat <robin@catalyst.net.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Tomás Cohen Arazi 2013-12-16 14:32:40 -03:00 committed by Galen Charlton
parent 9d9c413c42
commit 7ec644da06
9 changed files with 72 additions and 26 deletions

View file

@ -123,6 +123,50 @@ getinstancemysqldatabase() {
xmlstarlet sel -t -v 'yazgfs/config/database' "/etc/koha/sites/$1/koha-conf.xml" xmlstarlet sel -t -v 'yazgfs/config/database' "/etc/koha/sites/$1/koha-conf.xml"
} }
check_apache_config()
{
# Check that mpm_itk is installed and enabled
if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_itk'; then
# Check Apache version
APACHE_DISABLE_MPM_MSG=""
if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then
# mpm_event or mpm_worker need to be disabled first. mpm_itk depends
# on mpm_prefork, which is enabled if needed. See
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734865
if /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_event'; then
APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_event ;"
elif /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_worker'; then
APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_worker ;"
# else mpm_prefork: a2enmod mpm_itk works
fi
# else Apache 2.2: a2enmod mpm_itk works
fi
cat 1>&2 <<EOM
Koha requires mpm_itk to be enabled within Apache in order to run.
Typically this can be enabled with:
$APACHE_DISABLE_MPM_MSG sudo a2enmod mpm_itk
EOM
die
fi
# Check that mod_rewrite is installed and enabled.
if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'rewrite_module'; then
cat 1>&2 <<EOM
Koha requires mod_rewrite to be enabled within Apache in order to run.
Typically this can be enabled with:
sudo a2enmod rewrite
EOM
die
fi
}
set_biblios_indexing_mode() set_biblios_indexing_mode()
{ {
local indexing_mode=$1 local indexing_mode=$1
@ -373,7 +417,7 @@ elif [ "$CLO_MEMCACHED_SERVERS" != "" ] || \
Error: you provided memcached configuration switches but memcached is not enabled. 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 Please set USE_MEMCACHED="yes" on /etc/koha/koha-sites.conf or use the
--use-memcached optio switch to enable it. --use-memcached option switch to enable it.
EOF` EOF`
@ -391,18 +435,8 @@ then
die "This script must be run with root privileges." die "This script must be run with root privileges."
fi fi
# Check that mod_rewrite is installed so we can bail out if it's not. # Check everything is ok with Apache, die otherwise
if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'rewrite_module' check_apache_config
then
cat 1>&2 <<EOM
Koha requires mod_rewrite to be enabled within Apache in order to run.
Typically this can be enabled with:
sudo a2enmod rewrite
EOM
die
fi
opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN" opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN"
intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN" intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN"
@ -493,7 +527,7 @@ eof
# Generate and install Apache site-available file and log dir. # Generate and install Apache site-available file and log dir.
generate_config_file apache-site.conf.in \ generate_config_file apache-site.conf.in \
"/etc/apache2/sites-available/$name" "/etc/apache2/sites-available/$name.conf"
mkdir "/var/log/koha/$name" mkdir "/var/log/koha/$name"
chown "$username:$username" "/var/log/koha/$name" chown "$username:$username" "/var/log/koha/$name"

View file

@ -34,13 +34,14 @@ warn()
is_enabled() is_enabled()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if ! is_instance $instancename; then if ! is_instance $instancename; then
return 1 return 1
fi fi
if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
"/etc/apache2/sites-available/$instancename" ; then "$instancefile" ; then
return 1 return 1
else else
return 0 return 0
@ -63,10 +64,11 @@ is_instance()
disable_instance() disable_instance()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if is_enabled $instancename; then if is_enabled $instancename; then
sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-disable.conf\)$:\1:' \ sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-disable.conf\)$:\1:' \
"/etc/apache2/sites-available/$instancename" "$instancefile"
return 0 return 0
else else
return 1 return 1

View file

@ -54,14 +54,15 @@ mysqldump --databases --host="$mysqlhost" \
chown "root:$name-koha" "$dbdump" chown "root:$name-koha" "$dbdump"
chmod g+r "$dbdump" chmod g+r "$dbdump"
instancefile="$name.conf"
# Dump configs, logs, etc. # Dump configs, logs, etc.
metadump="$backupdir/$name-$date.tar.gz" metadump="$backupdir/$name-$date.tar.gz"
echo "* configs, logs to $metadump" echo "* configs, logs to $metadump"
tar -C / -czf "$metadump" \ tar -C / -czf "$metadump" \
"etc/koha/sites/$name" \ "etc/koha/sites/$name" \
"etc/apache2/sites-available/$name" \ "etc/apache2/sites-available/$instancefile" \
"etc/apache2/sites-enabled/$name" \ "etc/apache2/sites-enabled/$instancefile" \
"var/lib/koha/$name" \ "var/lib/koha/$name" \
"var/log/koha/$name" "var/log/koha/$name"

View file

@ -34,13 +34,14 @@ warn()
is_enabled() is_enabled()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if ! is_instance $instancename; then if ! is_instance $instancename; then
return 1 return 1
fi fi
if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
"/etc/apache2/sites-available/$instancename" ; then "$instancefile" ; then
return 1 return 1
else else
return 0 return 0
@ -63,10 +64,11 @@ is_instance()
enable_instance() enable_instance()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if ! is_enabled $instancename; then if ! is_enabled $instancename; then
sed -i 's:^\(\s*Include /etc/koha/apache-shared-disable.conf\)$:#\1:' \ sed -i 's:^\(\s*Include /etc/koha/apache-shared-disable.conf\)$:#\1:' \
"/etc/apache2/sites-available/$instancename" "$instancefile"
return 0 return 0
else else
return 1 return 1

View file

@ -28,9 +28,10 @@ die()
is_enabled() is_enabled()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ if grep '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
"/etc/apache2/sites-available/$instancename" > /dev/null "$instancefile" > /dev/null
then then
return 1 return 1
else else

View file

@ -68,8 +68,11 @@ eof
# If the daemon is not running already, we don't want to fail this loop. So bin the result code if this fails. # If the daemon is not running already, we don't want to fail this loop. So bin the result code if this fails.
koha-stop-zebra $name || /bin/true koha-stop-zebra $name || /bin/true
[ -f "/etc/apache2/sites-available/$name" ] && \
rm "/etc/apache2/sites-available/$name" instancefile="$name.conf"
[ -f "/etc/apache2/sites-available/$instancefile" ] && \
rm "/etc/apache2/sites-available/$instancefile"
[ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \ [ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \
rm "/etc/koha/sites/$name/koha-conf.xml" rm "/etc/koha/sites/$name/koha-conf.xml"
[ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \ [ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \

View file

@ -32,13 +32,14 @@ warn()
is_enabled() is_enabled()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if ! is_instance $instancename; then if ! is_instance $instancename; then
return 1 return 1
fi fi
if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
"/etc/apache2/sites-available/$instancename" ; then "$instancefile" ; then
return 1 return 1
else else
return 0 return 0

View file

@ -32,13 +32,14 @@ warn()
is_enabled() is_enabled()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if ! is_instance $instancename; then if ! is_instance $instancename; then
return 1 return 1
fi fi
if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
"/etc/apache2/sites-available/$instancename" ; then "$instancefile" ; then
return 1 return 1
else else
return 0 return 0

View file

@ -32,13 +32,14 @@ warn()
is_enabled() is_enabled()
{ {
local instancename=$1 local instancename=$1
local instancefile="/etc/apache2/sites-available/$instancename.conf"
if ! is_instance $instancename; then if ! is_instance $instancename; then
return 1 return 1
fi fi
if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \ if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-disable.conf' \
"/etc/apache2/sites-available/$instancename" ; then "$instancefile" ; then
return 1 return 1
else else
return 0 return 0