Commit b9fca014 authored by Alain Takoudjou's avatar Alain Takoudjou

Allow to send env variable and custom config to apache recipe

parent 25c5fba2
...@@ -33,6 +33,27 @@ from slapos.recipe.librecipe import GenericBaseRecipe ...@@ -33,6 +33,27 @@ from slapos.recipe.librecipe import GenericBaseRecipe
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
def __init__(self, buildout, name, options):
self.environ = {}
environment_section = options.get('environment-section', '').strip()
if environment_section and environment_section in buildout:
# Use environment variables from the designated config section.
self.environ.update(buildout[environment_section])
for variable in options.get('environment', '').splitlines():
if variable.strip():
try:
key, value = variable.split('=', 1)
self.environ[key.strip()] = value
except ValueError:
raise zc.buildout.UserError('Invalid environment variable definition: %s', variable)
# Extrapolate the environment variables using values from the current
# environment.
for key in self.environ:
self.environ[key] = self.environ[key] % os.environ
return GenericBaseRecipe.__init__(self, buildout, name, options)
def install(self): def install(self):
path_list = [] path_list = []
...@@ -50,26 +71,28 @@ class Recipe(GenericBaseRecipe): ...@@ -50,26 +71,28 @@ class Recipe(GenericBaseRecipe):
path_list.append(php_ini) path_list.append(php_ini)
# Install apache # Install apache
apache_config = dict( if self.optionIsTrue('default-conf', True):
pid_file=self.options['pid-file'], apache_config = dict(
lock_file=self.options['lock-file'], pid_file=self.options['pid-file'],
ip=self.options['ip'], lock_file=self.options['lock-file'],
port=self.options['port'], ip=self.options['ip'],
error_log=self.options['error-log'], port=self.options['port'],
access_log=self.options['access-log'], error_log=self.options['error-log'],
document_root=self.options['htdocs'], access_log=self.options['access-log'],
php_ini_dir=self.options['php-ini-dir'], document_root=self.options['htdocs'],
) php_ini_dir=self.options['php-ini-dir'],
httpd_conf = self.createFile(self.options['httpd-conf'], )
self.substituteTemplate(self.getTemplateFilename('apache.in'), httpd_conf = self.createFile(self.options['httpd-conf'],
apache_config) self.substituteTemplate(self.getTemplateFilename('apache.in'),
) apache_config)
path_list.append(httpd_conf) )
path_list.append(httpd_conf)
wrapper = self.createPythonScript(self.options['wrapper'], apache_args = [self.options['httpd-binary'], '-f', self.options['httpd-conf'],
'slapos.recipe.librecipe.execute.execute',
[self.options['httpd-binary'], '-f', self.options['httpd-conf'],
'-DFOREGROUND'] '-DFOREGROUND']
wrapper = self.createPythonScript(self.options['wrapper'],
'slapos.recipe.librecipe.execute.executee',
(apache_args, self.environ)
) )
path_list.append(wrapper) path_list.append(wrapper)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment