Skip to content

Commit b4495eb

Browse files
r0ckpineianw
authored andcommitted
Use mod_version to clean-up apache version matching
This change uses mod_version (shipped by default on everything we care about) to set-up version-specific config within apache rather than within devstack scripts. Clean up the horizon and keystone config file generation to use the internal apache matching. Since I6478db385fda2fa1c75ced12d3e886b2e1152852 the apache matching in 'functions' is actually duplicated. just leave get_apache_version in lib/apache as it is used for config-file name matching in there. Change-Id: I6478db385fda2fa1c75ced12d3e886b2e1152852
1 parent 3d458eb commit b4495eb

6 files changed

Lines changed: 20 additions & 31 deletions

File tree

files/apache-horizon.template

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717

1818
<Directory %HORIZON_DIR%/>
1919
Options Indexes FollowSymLinks MultiViews
20-
%HORIZON_REQUIRE%
2120
AllowOverride None
22-
Order allow,deny
23-
allow from all
21+
# Apache 2.4 uses mod_authz_host for access control now (instead of
22+
# "Allow")
23+
<IfVersion < 2.4>
24+
Order allow,deny
25+
Allow from all
26+
</IfVersion>
27+
<IfVersion >= 2.4>
28+
Require all granted
29+
</IfVersion>
2430
</Directory>
2531

2632
ErrorLog /var/log/%APACHE_NAME%/horizon_error.log

files/apache-keystone.template

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Listen %ADMINPORT%
66
WSGIProcessGroup keystone-public
77
WSGIScriptAlias / %PUBLICWSGI%
88
WSGIApplicationGroup %{GLOBAL}
9-
%ERRORLOGFORMAT%
9+
<IfVersion >= 2.4>
10+
ErrorLogFormat "%{cu}t %M"
11+
</IfVersion>
1012
ErrorLog /var/log/%APACHE_NAME%/keystone.log
1113
CustomLog /var/log/%APACHE_NAME%/access.log combined
1214
</VirtualHost>
@@ -16,7 +18,9 @@ Listen %ADMINPORT%
1618
WSGIProcessGroup keystone-admin
1719
WSGIScriptAlias / %ADMINWSGI%
1820
WSGIApplicationGroup %{GLOBAL}
19-
%ERRORLOGFORMAT%
21+
<IfVersion >= 2.4>
22+
ErrorLogFormat "%{cu}t %M"
23+
</IfVersion>
2024
ErrorLog /var/log/%APACHE_NAME%/keystone.log
2125
CustomLog /var/log/%APACHE_NAME%/access.log combined
2226
</VirtualHost>

functions

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ function function_exists {
2121
declare -f -F $1 > /dev/null
2222
}
2323

24-
# Checks if installed Apache is <= given version
25-
# $1 = x.y.z (version string of Apache)
26-
function check_apache_version {
27-
local cmd="apachectl"
28-
if ! [[ -x $(which apachectl 2>/dev/null) ]]; then
29-
cmd="/usr/sbin/apachectl"
30-
fi
31-
32-
local version=$($cmd -v | grep version | grep -Po 'Apache/\K[^ ]*')
33-
expr "$version" '>=' $1 > /dev/null
34-
}
35-
3624

3725
# Cleanup anything from /tmp on unstack
3826
# clean_tmp

lib/apache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ function install_apache_wsgi {
5959
else
6060
exit_distro_not_supported "apache installation"
6161
fi
62+
63+
# ensure mod_version enabled for <IfVersion ...>. This is
64+
# built-in statically on anything recent, but precise (2.2)
65+
# doesn't have it enabled
66+
sudo a2enmod version || true
6267
}
6368

6469
# get_apache_version() - return the version of Apache installed

lib/horizon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ function init_horizon {
120120
# Create an empty directory that apache uses as docroot
121121
sudo mkdir -p $HORIZON_DIR/.blackhole
122122

123-
# Apache 2.4 uses mod_authz_host for access control now (instead of "Allow")
124-
local horizon_require=''
125-
if check_apache_version "2.4" ; then
126-
horizon_require='Require all granted'
127-
fi
128-
129123
local horizon_conf=$(apache_site_config_for horizon)
130124

131125
# Configure apache to run horizon
@@ -135,7 +129,6 @@ function init_horizon {
135129
s,%HORIZON_DIR%,$HORIZON_DIR,g;
136130
s,%APACHE_NAME%,$APACHE_NAME,g;
137131
s,%DEST%,$DEST,g;
138-
s,%HORIZON_REQUIRE%,$horizon_require,g;
139132
\" $FILES/apache-horizon.template >$horizon_conf"
140133

141134
if is_ubuntu; then

lib/keystone

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ function _config_keystone_apache_wsgi {
125125
local keystone_apache_conf=$(apache_site_config_for keystone)
126126
local apache_version=$(get_apache_version)
127127

128-
if [[ ${apache_version#*\.} -ge 4 ]]; then
129-
# Apache 2.4 supports custom error log formats
130-
# this should mirror the original log formatting.
131-
local errorlogformat='ErrorLogFormat "%{cu}t %M"'
132-
fi
133-
134128
# copy proxy vhost and wsgi file
135129
sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/main
136130
sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/admin
@@ -143,7 +137,6 @@ function _config_keystone_apache_wsgi {
143137
s|%PUBLICWSGI%|$KEYSTONE_WSGI_DIR/main|g;
144138
s|%ADMINWSGI%|$KEYSTONE_WSGI_DIR/admin|g;
145139
s|%USER%|$STACK_USER|g
146-
s|%ERRORLOGFORMAT%|$errorlogformat|g;
147140
" -i $keystone_apache_conf
148141
enable_apache_site keystone
149142
}

0 commit comments

Comments
 (0)