update HTTP service to support apache 2.4 on Ubuntu 14.04 (fixes bug #261)

(Boeing r1895)
This commit is contained in:
ahrenholz 2014-10-30 18:13:43 +00:00
parent 503713f0bc
commit f61522207d

View file

@ -1,6 +1,6 @@
# #
# CORE # CORE
# Copyright (c)2010-2012 the Boeing Company. # Copyright (c)2010-2014 the Boeing Company.
# See the LICENSE file included in this distribution. # See the LICENSE file included in this distribution.
# #
# author: Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com> # author: Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
@ -394,6 +394,8 @@ class HttpService(UtilService):
_startup = ("chown www-data /var/lock/apache2", "apache2ctl start",) _startup = ("chown www-data /var/lock/apache2", "apache2ctl start",)
_shutdown = ("apache2ctl stop",) _shutdown = ("apache2ctl stop",)
_validate = ("pidof apache2",) _validate = ("pidof apache2",)
APACHEVER22, APACHEVER24 = (22, 24)
@classmethod @classmethod
def generateconfig(cls, node, filename, services): def generateconfig(cls, node, filename, services):
@ -408,16 +410,55 @@ class HttpService(UtilService):
else: else:
return "" return ""
@classmethod
def detectversionfromcmd(cls):
''' Detect the apache2 version using the 'a2query' command.
'''
try:
status, result = cmdresult(['a2query', '-v'])
except Exception:
status = -1
if status == 0 and result[:3] == '2.4':
return cls.APACHEVER24
return cls.APACHEVER22
@classmethod @classmethod
def generateapache2conf(cls, node, filename, services): def generateapache2conf(cls, node, filename, services):
return """\ lockstr = { cls.APACHEVER22:
# apache2.conf generated by utility.py:HttpService 'LockFile ${APACHE_LOCK_DIR}/accept.lock\n',
LockFile ${APACHE_LOCK_DIR}/accept.lock cls.APACHEVER24:
'Mutex file:${APACHE_LOCK_DIR} default\n', }
mpmstr = { cls.APACHEVER22: '', cls.APACHEVER24:
'LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n', }
permstr = { cls.APACHEVER22:
' Order allow,deny\n Deny from all\n Satisfy all\n',
cls.APACHEVER24:
' Require all denied\n', }
authstr = { cls.APACHEVER22:
'LoadModule authz_default_module /usr/lib/apache2/modules/mod_authz_default.so\n',
cls.APACHEVER24:
'LoadModule authz_core_module /usr/lib/apache2/modules/mod_authz_core.so\n', }
permstr2 = { cls.APACHEVER22:
'\t\tOrder allow,deny\n\t\tallow from all\n',
cls.APACHEVER24:
'\t\tRequire all granted\n', }
version = cls.detectversionfromcmd()
cfg ="# apache2.conf generated by utility.py:HttpService\n"
cfg += lockstr[version]
cfg += """\
PidFile ${APACHE_PID_FILE} PidFile ${APACHE_PID_FILE}
Timeout 300 Timeout 300
KeepAlive On KeepAlive On
MaxKeepAliveRequests 100 MaxKeepAliveRequests 100
KeepAliveTimeout 5 KeepAliveTimeout 5
"""
cfg += mpmstr[version]
cfg += """\
<IfModule mpm_prefork_module> <IfModule mpm_prefork_module>
StartServers 5 StartServers 5
@ -453,9 +494,9 @@ Group ${APACHE_RUN_GROUP}
AccessFileName .htaccess AccessFileName .htaccess
<Files ~ "^\.ht"> <Files ~ "^\.ht">
Order allow,deny """
Deny from all cfg += permstr[version]
Satisfy all cfg += """\
</Files> </Files>
DefaultType None DefaultType None
@ -469,7 +510,9 @@ LogLevel warn
#Include mods-enabled/*.conf #Include mods-enabled/*.conf
LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.so LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.so
LoadModule authz_default_module /usr/lib/apache2/modules/mod_authz_default.so """
cfg += authstr[version]
cfg += """\
LoadModule authz_host_module /usr/lib/apache2/modules/mod_authz_host.so LoadModule authz_host_module /usr/lib/apache2/modules/mod_authz_host.so
LoadModule authz_user_module /usr/lib/apache2/modules/mod_authz_user.so LoadModule authz_user_module /usr/lib/apache2/modules/mod_authz_user.so
LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so
@ -506,8 +549,9 @@ TraceEnable Off
<Directory /var/www/> <Directory /var/www/>
Options Indexes FollowSymLinks MultiViews Options Indexes FollowSymLinks MultiViews
AllowOverride None AllowOverride None
Order allow,deny """
allow from all cfg += permstr2[version]
cfg += """\
</Directory> </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn LogLevel warn
@ -515,6 +559,7 @@ TraceEnable Off
</VirtualHost> </VirtualHost>
""" """
return cfg
@classmethod @classmethod
def generateenvvars(cls, node, filename, services): def generateenvvars(cls, node, filename, services):