Browse code

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

Noboru Iwamatsu authored on 2014/07/02 18:31:31
Showing 6 changed files
... ...
@@ -17,10 +17,16 @@
17 17
 
18 18
     <Directory %HORIZON_DIR%/>
19 19
         Options Indexes FollowSymLinks MultiViews
20
-        %HORIZON_REQUIRE%
21 20
         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>
24 30
     </Directory>
25 31
 
26 32
     ErrorLog /var/log/%APACHE_NAME%/horizon_error.log
... ...
@@ -6,7 +6,9 @@ Listen %ADMINPORT%
6 6
     WSGIProcessGroup keystone-public
7 7
     WSGIScriptAlias / %PUBLICWSGI%
8 8
     WSGIApplicationGroup %{GLOBAL}
9
-    %ERRORLOGFORMAT%
9
+    <IfVersion >= 2.4>
10
+      ErrorLogFormat "%{cu}t %M"
11
+    </IfVersion>
10 12
     ErrorLog /var/log/%APACHE_NAME%/keystone.log
11 13
     CustomLog /var/log/%APACHE_NAME%/access.log combined
12 14
 </VirtualHost>
... ...
@@ -16,7 +18,9 @@ Listen %ADMINPORT%
16 16
     WSGIProcessGroup keystone-admin
17 17
     WSGIScriptAlias / %ADMINWSGI%
18 18
     WSGIApplicationGroup %{GLOBAL}
19
-    %ERRORLOGFORMAT%
19
+    <IfVersion >= 2.4>
20
+      ErrorLogFormat "%{cu}t %M"
21
+    </IfVersion>
20 22
     ErrorLog /var/log/%APACHE_NAME%/keystone.log
21 23
     CustomLog /var/log/%APACHE_NAME%/access.log combined
22 24
 </VirtualHost>
... ...
@@ -21,18 +21,6 @@ function function_exists {
21 21
     declare -f -F $1 > /dev/null
22 22
 }
23 23
 
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
-
36 24
 
37 25
 # Cleanup anything from /tmp on unstack
38 26
 # clean_tmp
... ...
@@ -59,6 +59,11 @@ function install_apache_wsgi {
59 59
     else
60 60
         exit_distro_not_supported "apache installation"
61 61
     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
62 67
 }
63 68
 
64 69
 # get_apache_version() - return the version of Apache installed
... ...
@@ -120,12 +120,6 @@ function init_horizon {
120 120
     # Create an empty directory that apache uses as docroot
121 121
     sudo mkdir -p $HORIZON_DIR/.blackhole
122 122
 
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
-
129 123
     local horizon_conf=$(apache_site_config_for horizon)
130 124
 
131 125
     # Configure apache to run horizon
... ...
@@ -135,7 +129,6 @@ function init_horizon {
135 135
         s,%HORIZON_DIR%,$HORIZON_DIR,g;
136 136
         s,%APACHE_NAME%,$APACHE_NAME,g;
137 137
         s,%DEST%,$DEST,g;
138
-        s,%HORIZON_REQUIRE%,$horizon_require,g;
139 138
     \" $FILES/apache-horizon.template >$horizon_conf"
140 139
 
141 140
     if is_ubuntu; then
... ...
@@ -125,12 +125,6 @@ function _config_keystone_apache_wsgi {
125 125
     local keystone_apache_conf=$(apache_site_config_for keystone)
126 126
     local apache_version=$(get_apache_version)
127 127
 
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
-
134 128
     # copy proxy vhost and wsgi file
135 129
     sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/main
136 130
     sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/admin
... ...
@@ -143,7 +137,6 @@ function _config_keystone_apache_wsgi {
143 143
         s|%PUBLICWSGI%|$KEYSTONE_WSGI_DIR/main|g;
144 144
         s|%ADMINWSGI%|$KEYSTONE_WSGI_DIR/admin|g;
145 145
         s|%USER%|$STACK_USER|g
146
-        s|%ERRORLOGFORMAT%|$errorlogformat|g;
147 146
     " -i $keystone_apache_conf
148 147
     enable_apache_site keystone
149 148
 }