Allow to provide backend-path.
[slapos.git] / slapos / recipe / apache_zope_backend / __init__.py
1 ##############################################################################
2 #
3 # Copyright (c) 2011 Vifib SARL and Contributors. All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsibility of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # guarantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #
26 ##############################################################################
27 from slapos.recipe.librecipe import GenericBaseRecipe
28 import pkg_resources
29
30 class Recipe(GenericBaseRecipe):
31 def install(self):
32 path_list = []
33 ip = self.options['ip']
34 port = self.options['port']
35 backend = self.options['backend']
36
37 apache_conf = dict()
38
39 scheme = self.options['scheme']
40 if scheme == 'http':
41 required_path_list = []
42 apache_conf['ssl_snippet'] = ''
43 elif scheme == 'https':
44 key = self.options['key-file']
45 certificate = self.options['cert-file']
46 required_path_list = [key, certificate]
47 apache_conf['key'] = key
48 apache_conf['certificate'] = certificate
49 apache_conf['ssl_session_cache'] = self.options['ssl-session-cache']
50 apache_conf['ssl_snippet'] = pkg_resources.resource_string(__name__,
51 'template/snippet.ssl.in') % apache_conf
52 if 'ssl-authentication' in self.options and self.optionIsTrue(
53 'ssl-authentication'):
54 apache_conf['ssl_snippet'] += pkg_resources.resource_string(__name__,
55 'template/snippet.ssl.ca.in') % dict(
56 ca_certificate=self.options['ssl-authentication-certificate'],
57 ca_crl=self.options['ssl-authentication-crl']
58 )
59 else:
60 raise ValueError, "Unsupported scheme %s" % scheme
61
62 access_control_string = self.options['access-control-string']
63 apache_conf['pid_file'] = self.options['pid-file']
64 apache_conf['lock_file'] = self.options['lock-file']
65 apache_conf['ip'] = ip
66 apache_conf['port'] = port
67 apache_conf['server_admin'] = 'admin@'
68 apache_conf['error_log'] = self.options['error-log']
69 apache_conf['access_log'] = self.options['access-log']
70 apache_conf['server_name'] = '%s' % apache_conf['ip']
71 apache_conf['path'] = '/'
72 apache_conf['access_control_string'] = access_control_string
73 apache_conf['rewrite_rule'] = "RewriteRule (.*) %s%s [L,P]" % (backend,
74 self.options.get('backend-path', '/'))
75 apache_conf_string = pkg_resources.resource_string(__name__,
76 'template/apache.zope.conf.in') % apache_conf
77 apache_config_file = self.createFile(self.options['configuration-file'],
78 apache_conf_string)
79 path_list.append(apache_config_file)
80 wrapper = self.createPythonScript(self.options['wrapper'], __name__ +
81 '.apache.runApache', [
82 dict(
83 required_path_list=required_path_list,
84 binary=self.options['apache-binary'],
85 config=apache_config_file
86 )
87 ])
88 path_list.append(wrapper)
89 return path_list