Browse code

Use the apache 2.4 ErrorLogFormat directive

Use the new ErrorLogFormat directive to make the Keystone logs
under Apache to look like the standard oslo log format.

Change-Id: Ie823abf2fa06b8ce22027c21bef455808a4a768e

Morgan Fainberg authored on 2014/06/25 13:33:39
Showing 3 changed files
... ...
@@ -6,6 +6,7 @@ Listen %ADMINPORT%
6 6
     WSGIProcessGroup keystone-public
7 7
     WSGIScriptAlias / %PUBLICWSGI%
8 8
     WSGIApplicationGroup %{GLOBAL}
9
+    %ERRORLOGFORMAT%
9 10
     ErrorLog /var/log/%APACHE_NAME%/keystone.log
10 11
     CustomLog /var/log/%APACHE_NAME%/access.log combined
11 12
 </VirtualHost>
... ...
@@ -15,6 +16,7 @@ Listen %ADMINPORT%
15 15
     WSGIProcessGroup keystone-admin
16 16
     WSGIScriptAlias / %ADMINWSGI%
17 17
     WSGIApplicationGroup %{GLOBAL}
18
+    %ERRORLOGFORMAT%
18 19
     ErrorLog /var/log/%APACHE_NAME%/keystone.log
19 20
     CustomLog /var/log/%APACHE_NAME%/access.log combined
20 21
 </VirtualHost>
... ...
@@ -61,6 +61,28 @@ function install_apache_wsgi {
61 61
     fi
62 62
 }
63 63
 
64
+# get_apache_version() - return the version of Apache installed
65
+# This function is used to determine the Apache version installed. There are
66
+# various differences between Apache 2.2 and 2.4 that warrant special handling.
67
+function get_apache_version {
68
+    if is_ubuntu; then
69
+        local version_str=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/)
70
+    elif is_fedora; then
71
+        local version_str=$(rpm -qa --queryformat '%{VERSION}' httpd)
72
+    elif is_suse; then
73
+        local version_str=$(rpm -qa --queryformat '%{VERSION}' apache2)
74
+    else
75
+        exit_distro_not_supported "cannot determine apache version"
76
+    fi
77
+    if [[ "$version_str" =~ ^2\.2\. ]]; then
78
+        echo "2.2"
79
+    elif [[ "$version_str" =~ ^2\.4\. ]]; then
80
+        echo "2.4"
81
+    else
82
+        exit_distro_not_supported "apache version not supported"
83
+    fi
84
+}
85
+
64 86
 # apache_site_config_for() - The filename of the site's configuration file.
65 87
 # This function uses the global variables APACHE_NAME and APACHE_CONF_DIR.
66 88
 #
... ...
@@ -87,8 +109,8 @@ function install_apache_wsgi {
87 87
 function apache_site_config_for {
88 88
     local site=$@
89 89
     if is_ubuntu; then
90
-        local apache_version=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/)
91
-        if [[ "$apache_version" =~ ^2\.2\. ]]; then
90
+        local apache_version=$(get_apache_version)
91
+        if [[ "$apache_version" == "2.2" ]]; then
92 92
             # Ubuntu 12.04 - Apache 2.2
93 93
             echo $APACHE_CONF_DIR/${site}
94 94
         else
... ...
@@ -123,6 +123,13 @@ function _config_keystone_apache_wsgi {
123 123
     sudo mkdir -p $KEYSTONE_WSGI_DIR
124 124
 
125 125
     local keystone_apache_conf=$(apache_site_config_for keystone)
126
+    local apache_version=$(get_apache_version)
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
126 133
 
127 134
     # copy proxy vhost and wsgi file
128 135
     sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/main
... ...
@@ -136,6 +143,7 @@ function _config_keystone_apache_wsgi {
136 136
         s|%PUBLICWSGI%|$KEYSTONE_WSGI_DIR/main|g;
137 137
         s|%ADMINWSGI%|$KEYSTONE_WSGI_DIR/admin|g;
138 138
         s|%USER%|$STACK_USER|g
139
+        s|%ERRORLOGFORMAT%|$errorlogformat|g;
139 140
     " -i $keystone_apache_conf
140 141
     enable_apache_site keystone
141 142
 }