__init__.py 22.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################
from slapos.recipe.librecipe import BaseSlapRecipe
import os
import pkg_resources
import hashlib
import sys
import zc.buildout
import zc.recipe.egg
import ConfigParser
35
import re
36 37 38


class Recipe(BaseSlapRecipe):
39

40 41
  def getTemplateFilename(self, template_name):
    return pkg_resources.resource_filename(__name__,
42
        'template/%s' % template_name)
43 44

  def _install(self):
45 46 47 48 49 50 51 52
    # Check for mandatory arguments
    frontend_domain_name = self.parameter_dict.get("domain")
    if frontend_domain_name is None:
      raise zc.buildout.UserError('No domain name specified. Please define '
          'the "domain" instance parameter.')

    # Define optional arguments
    frontend_port_number = self.parameter_dict.get("port", 4443)
53 54
    frontend_plain_http_port_number = self.parameter_dict.get(
        "plain_http_port", 8080)
55 56 57
    base_varnish_port = 26009
    slave_instance_list = self.parameter_dict.get("slave_instance_list", [])

58 59
    self.path_list = []
    self.requirements, self.ws = self.egg.working_set()
Rafael Monnerat's avatar
Rafael Monnerat committed
60

61
    # self.cron_d is a directory, where cron jobs can be registered
Rafael Monnerat's avatar
Rafael Monnerat committed
62
    self.cron_d = self.installCrond()
63 64
    self.logrotate_d, self.logrotate_backup = self.installLogrotate()
    self.killpidfromfile = zc.buildout.easy_install.scripts(
65
        [('killpidfromfile', 'slapos.recipe.erp5.killpidfromfile',
66 67
          'killpidfromfile')], self.ws, sys.executable, self.bin_directory)[0]
    self.path_list.append(self.killpidfromfile)
68

69
    rewrite_rule_list = []
70
    rewrite_rule_zope_list = []
71
    slave_dict = {}
72
    service_dict = {}
73 74

    # Check if default port
75 76
    if frontend_port_number is 443 or frontend_port_number is 80:
      port_snippet = ""
77
    else:
78
      port_snippet = ":%s" % frontend_port_number
79

80
    for slave_instance in slave_instance_list:
81
      backend_url = slave_instance.get("url", None)
82
      reference = slave_instance.get("slave_reference")
83 84 85
      # Set scheme (http? https?)
      # Future work may allow to choose between http and https (or both?)
      scheme = 'https://'
86

87 88
      self.logger.info('processing slave instance: %s' % reference)

89
      # Check for mandatory slave fields
90
      if backend_url is None:
91 92
        self.logger.warn('No "url" parameter is defined for %s slave'\
            'instance. Ignoring it.' % reference)
93
        continue
94

95 96 97 98 99
      # Check for custom domain (like mypersonaldomain.com)
      # If no custom domain, use generated one
      domain = slave_instance.get('custom_domain', 
          "%s.%s" % (reference.replace("-", "").lower(), frontend_domain_name))
      slave_dict[reference] = "%s%s%s/" % (scheme, domain, port_snippet)
100

101
      # Check if we want varnish+stunnel cache.
102 103 104
      if slave_instance.get("enable_cache", "").upper() in ('1', 'TRUE'):
        # XXX-Cedric : need to refactor to clean code? (to many variables)
        rewrite_rule = self.configureVarnishSlave(
105
            base_varnish_port, backend_url, reference, service_dict, domain)
106
        base_varnish_port += 2
107
      else:
108
        rewrite_rule = "%s %s" % (domain, backend_url)
109 110 111 112 113 114 115

      # Finally, if successful, we add the rewrite rule to our list of rules
      if rewrite_rule:
        # We check if we have a zope slave. It requires different rewrite
        # rule structure.
        # So we will have one RewriteMap for normal websites, and one
        # RewriteMap for Zope Virtual Host Monster websites.
116
        if slave_instance.get("type", "").lower() in ['zope']:
117 118 119
          rewrite_rule_zope_list.append(rewrite_rule)
        else:
          rewrite_rule_list.append(rewrite_rule)
120

121
    # Certificate stuff
122 123 124 125 126 127 128 129 130 131
    valid_certificate_str = self.parameter_dict.get("domain_ssl_ca_cert")
    valid_key_str = self.parameter_dict.get("domain_ssl_ca_key")
    if valid_certificate_str is None and valid_key_str is None:
      ca_conf = self.installCertificateAuthority()
      key, certificate = self.requestCertificate(frontend_domain_name)
    else:
      ca_conf = self.installValidCertificateAuthority(
          frontend_domain_name, valid_certificate_str, valid_key_str)
      key = ca_conf.pop("key")
      certificate = ca_conf.pop("certificate")
132
    if service_dict != {}:
133 134 135 136 137
      if valid_certificate_str is not None and valid_key_str is not None:
        self.installCertificateAuthority()
        stunnel_key, stunnel_certificate = \
            self.requestCertificate(frontend_domain_name)
      else:
138
        stunnel_key, stunnel_certificate = key, certificate
139
      self.installStunnel(service_dict,
140
        stunnel_certificate, stunnel_key,
141 142
        ca_conf["ca_crl"],
        ca_conf["certificate_authority_path"])
143

144
    apache_parameter_dict = self.installFrontendApache(
145
        ip_list=["[%s]" % self.getGlobalIPv6Address(),
146
                 self.getLocalIPv4Address()],
147
        port=frontend_port_number,
148
        plain_http_port=frontend_plain_http_port_number,
149 150
        name=frontend_domain_name,
        rewrite_rule_list=rewrite_rule_list,
151
        rewrite_rule_zope_list=rewrite_rule_zope_list,
152
        key=key, certificate=certificate)
153

154
    # Send connection informations about each slave
155 156 157
    for reference, url in slave_dict.iteritems():
      self.setConnectionDict(dict(site_url=url), reference)

158
    # Then set it for master instance
159 160
    self.setConnectionDict(
      dict(site_url=apache_parameter_dict["site_url"],
161
           domain_ipv6_address=self.getGlobalIPv6Address(),
162
           domain_ipv4_address=self.getLocalIPv4Address()))
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

    # Promises
    promise_config = dict(
      hostname=self.getGlobalIPv6Address(),
      port=frontend_port_number,
      python_path=sys.executable,
    )
    promise_v6 = self.createPromiseWrapper(
      'apache_ipv6',
      self.substituteTemplate(
          pkg_resources.resource_filename(
              'slapos.recipe.check_port_listening',
          'template/socket_connection_attempt.py.in'),
        promise_config))
    self.path_list.append(promise_v6)

    promise_config = dict(
      hostname=self.getLocalIPv4Address(),
      port=frontend_port_number,
      python_path=sys.executable,
    )
    promise_v4 = self.createPromiseWrapper(
      'apache_ipv4',
      self.substituteTemplate(
          pkg_resources.resource_filename(
              'slapos.recipe.check_port_listening',
          'template/socket_connection_attempt.py.in'),
        promise_config))
    self.path_list.append(promise_v4)

193 194
    return self.path_list

195 196
  def configureVarnishSlave(self, base_varnish_port, url, reference,
      service_dict, domain):
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    # Varnish should use stunnel to connect to the backend
    base_varnish_control_port = base_varnish_port
    base_varnish_port += 1
    # Use regex
    host_regex = "((\[\w*|[0-9]+\.)(\:|)).*(\]|\.[0-9]+)"
    slave_host = re.search(host_regex, url).group(0)
    port_regex = "\w+(\/|)$"
    matcher = re.search(port_regex, url)
    if matcher is not None:
      slave_port = matcher.group(0)
      slave_port = slave_port.replace("/", "")
    elif url.startswith("https://"):
      slave_port = 443
    else:
      slave_port = 80
    service_name = "varnish_%s" % reference
    varnish_ip = self.getLocalIPv4Address()
    stunnel_port = base_varnish_port + 1
    self.installVarnishCache(service_name,
      ip=varnish_ip,
      port=base_varnish_port,
      control_port=base_varnish_control_port,
      backend_host=varnish_ip,
      backend_port=stunnel_port,
      size="1G")
    service_dict[service_name] = dict(public_ip=varnish_ip,
        public_port=stunnel_port,
        private_ip=slave_host.replace("[", "").replace("]", ""),
        private_port=slave_port)
226 227
    return "%s http://%s:%s" % \
        (domain, varnish_ip, base_varnish_port)
228

229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
  def installLogrotate(self):
    """Installs logortate main configuration file and registers its to cron"""
    logrotate_d = os.path.abspath(os.path.join(self.etc_directory,
      'logrotate.d'))
    self._createDirectory(logrotate_d)
    logrotate_backup = self.createBackupDirectory('logrotate')
    logrotate_conf = self.createConfigurationFile("logrotate.conf",
        "include %s" % logrotate_d)
    logrotate_cron = os.path.join(self.cron_d, 'logrotate')
    state_file = os.path.join(self.data_root_directory, 'logrotate.status')
    open(logrotate_cron, 'w').write('0 0 * * * %s -s %s %s' %
        (self.options['logrotate_binary'], state_file, logrotate_conf))
    self.path_list.extend([logrotate_d, logrotate_conf, logrotate_cron])
    return logrotate_d, logrotate_backup

  def registerLogRotation(self, name, log_file_list, postrotate_script):
    """Register new log rotation requirement"""
    open(os.path.join(self.logrotate_d, name), 'w').write(
        self.substituteTemplate(self.getTemplateFilename(
          'logrotate_entry.in'),
          dict(file_list=' '.join(['"'+q+'"' for q in log_file_list]),
            postrotate=postrotate_script, olddir=self.logrotate_backup)))

  def requestCertificate(self, name):
    hash = hashlib.sha512(name).hexdigest()
    key = os.path.join(self.ca_private, hash + self.ca_key_ext)
    certificate = os.path.join(self.ca_certs, hash + self.ca_crt_ext)
    parser = ConfigParser.RawConfigParser()
    parser.add_section('certificate')
    parser.set('certificate', 'name', name)
    parser.set('certificate', 'key_file', key)
    parser.set('certificate', 'certificate_file', certificate)
    parser.write(open(os.path.join(self.ca_request_dir, hash), 'w'))
    return key, certificate

Rafael Monnerat's avatar
Rafael Monnerat committed
264 265 266 267 268 269 270 271 272 273 274 275 276
  def installCrond(self):
   timestamps = self.createDataDirectory('cronstamps')
   cron_output = os.path.join(self.log_directory, 'cron-output')
   self._createDirectory(cron_output)
   catcher = zc.buildout.easy_install.scripts([('catchcron',
     __name__ + '.catdatefile', 'catdatefile')], self.ws, sys.executable,
     self.bin_directory, arguments=[cron_output])[0]
   self.path_list.append(catcher)
   cron_d = os.path.join(self.etc_directory, 'cron.d')
   crontabs = os.path.join(self.etc_directory, 'crontabs')
   self._createDirectory(cron_d)
   self._createDirectory(crontabs)
   wrapper = zc.buildout.easy_install.scripts([('crond',
Gabriel Monnerat's avatar
Gabriel Monnerat committed
277
     'slapos.recipe.librecipe.execute', 'execute')], self.ws, sys.executable,
Rafael Monnerat's avatar
Rafael Monnerat committed
278 279 280 281 282 283 284
     self.wrapper_directory, arguments=[
       self.options['dcrond_binary'].strip(), '-s', cron_d, '-c', crontabs,
       '-t', timestamps, '-f', '-l', '5', '-M', catcher]
     )[0]
   self.path_list.append(wrapper)
   return cron_d

285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
  def installValidCertificateAuthority(self, domain_name, certificate, key):
    ca_dir = os.path.join(self.data_root_directory, 'ca')
    ca_private = os.path.join(ca_dir, 'private')
    ca_certs = os.path.join(ca_dir, 'certs')
    ca_crl = os.path.join(ca_dir, 'crl')
    self._createDirectory(ca_dir)
    for path in (ca_private, ca_certs, ca_crl):
      self._createDirectory(path)
    key_path = os.path.join(ca_private, domain_name + ".key")
    certificate_path = os.path.join(ca_certs, domain_name + ".crt")
    self._writeFile(key_path, key)
    self._writeFile(certificate_path, certificate)
    return dict(certificate_authority_path=ca_dir,
        ca_crl=ca_crl,
        certificate=certificate_path,
        key=key_path)

302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
  def installCertificateAuthority(self, ca_country_code='XX',
      ca_email='xx@example.com', ca_state='State', ca_city='City',
      ca_company='Company'):
    backup_path = self.createBackupDirectory('ca')
    self.ca_dir = os.path.join(self.data_root_directory, 'ca')
    self._createDirectory(self.ca_dir)
    self.ca_request_dir = os.path.join(self.ca_dir, 'requests')
    self._createDirectory(self.ca_request_dir)
    config = dict(ca_dir=self.ca_dir, request_dir=self.ca_request_dir)
    self.ca_private = os.path.join(self.ca_dir, 'private')
    self.ca_certs = os.path.join(self.ca_dir, 'certs')
    self.ca_crl = os.path.join(self.ca_dir, 'crl')
    self.ca_newcerts = os.path.join(self.ca_dir, 'newcerts')
    self.ca_key_ext = '.key'
    self.ca_crt_ext = '.crt'
    for d in [self.ca_private, self.ca_crl, self.ca_newcerts, self.ca_certs]:
      self._createDirectory(d)
    for f in ['crlnumber', 'serial']:
      if not os.path.exists(os.path.join(self.ca_dir, f)):
        open(os.path.join(self.ca_dir, f), 'w').write('01')
    if not os.path.exists(os.path.join(self.ca_dir, 'index.txt')):
      open(os.path.join(self.ca_dir, 'index.txt'), 'w').write('')
    openssl_configuration = os.path.join(self.ca_dir, 'openssl.cnf')
    config.update(
        working_directory=self.ca_dir,
        country_code=ca_country_code,
        state=ca_state,
        city=ca_city,
        company=ca_company,
        email_address=ca_email,
    )
    self._writeFile(openssl_configuration, pkg_resources.resource_string(
      __name__, 'template/openssl.cnf.ca.in') % config)
    self.path_list.extend(zc.buildout.easy_install.scripts([
336
      ('certificate_authority', __name__ + '.certificate_authority',
337
         'runCertificateAuthority')],
338 339 340 341 342 343 344 345
        self.ws, sys.executable, self.wrapper_directory, arguments=[dict(
          openssl_configuration=openssl_configuration,
          openssl_binary=self.options['openssl_binary'],
          certificate=os.path.join(self.ca_dir, 'cacert.pem'),
          key=os.path.join(self.ca_private, 'cakey.pem'),
          crl=os.path.join(self.ca_crl),
          request_dir=self.ca_request_dir
          )]))
346

347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
    # configure backup
    backup_cron = os.path.join(self.cron_d, 'ca_rdiff_backup')
    open(backup_cron, 'w').write(
        '''0 0 * * * %(rdiff_backup)s %(source)s %(destination)s'''%dict(
          rdiff_backup=self.options['rdiff_backup_binary'],
          source=self.ca_dir,
          destination=backup_path))
    self.path_list.append(backup_cron)

    return dict(
      ca_certificate=os.path.join(config['ca_dir'], 'cacert.pem'),
      ca_crl=os.path.join(config['ca_dir'], 'crl'),
      certificate_authority_path=config['ca_dir']
    )

362
  def _getApacheConfigurationDict(self, name, ip_list, port):
363
    apache_conf = dict()
364
    apache_conf['server_name'] = name
365
    apache_conf['pid_file'] = os.path.join(self.run_directory,
366
        name + '.pid')
367
    apache_conf['lock_file'] = os.path.join(self.run_directory,
368
        name + '.lock')
369 370
    apache_conf['document_root'] = os.path.join(self.data_root_directory,
        'htdocs')
371
    apache_conf['ip_list'] = ip_list
372 373 374
    apache_conf['port'] = port
    apache_conf['server_admin'] = 'admin@'
    apache_conf['error_log'] = os.path.join(self.log_directory,
375
        'frontend-apache-error.log')
376
    apache_conf['access_log'] = os.path.join(self.log_directory,
377
        'frontend-apache-access.log')
378
    self.registerLogRotation(name, [apache_conf['error_log'],
379 380 381 382
      apache_conf['access_log']], self.killpidfromfile + ' ' +
      apache_conf['pid_file'] + ' SIGUSR1')
    return apache_conf

383 384 385 386 387 388 389 390 391 392
  def installVarnishCache(self, name, ip, port, control_port, backend_host,
                                backend_port, size="1G"):
    """
      Install a varnish daemon for a certain address
    """
    directory = self.createDataDirectory(name)
    varnish_config = dict(
      directory=directory,
      pid = "%s/varnish.pid" % directory,
      port="%s:%s" % (ip, port),
393
      varnishd_binary=self.options["varnishd_binary"],
394 395 396 397
      control_port="%s:%s" % (ip, control_port),
      storage="file,%s/storage.bin,%s" % (directory, size))

    config_file = self.createConfigurationFile("%s.conf" % name,
398 399
      self.substituteTemplate(self.getTemplateFilename('varnish.vcl.in'),
        dict(backend_host=backend_host, backend_port=backend_port)))
400

401
    varnish_argument_list = [varnish_config['varnishd_binary'].strip(),
402 403 404 405
        "-F", "-n", directory, "-P", varnish_config["pid"], "-p",
        "cc_command=exec %s " % self.options["gcc_binary"] +\
            "-fpic -shared -o %o %s",
        "-f", config_file,
406 407
        "-a", varnish_config["port"], "-T", varnish_config["control_port"],
        "-s", varnish_config["storage"]]
408
    environment = dict(PATH=self.options["binutils_directory"])
Gabriel Monnerat's avatar
Gabriel Monnerat committed
409
    wrapper = zc.buildout.easy_install.scripts([(name,
410 411 412
      'slapos.recipe.librecipe.execute', 'executee')], self.ws,
      sys.executable, self.wrapper_directory, arguments=[varnish_argument_list,
      environment])[0]
413
    self.path_list.append(wrapper)
414 415

    return varnish_config
416

417 418
  def installStunnel(self, service_dict, certificate,
      key, ca_crl, ca_path):
419
    """Installs stunnel
420
      service_dict =
421
        { name: (public_ip, private_ip, public_port, private_port),}
422 423
    """
    template_filename = self.getTemplateFilename('stunnel.conf.in')
424
    template_entry_filename = self.getTemplateFilename('stunnel.conf.entry.in')
425 426 427 428 429 430

    log = os.path.join(self.log_directory, 'stunnel.log')
    pid_file = os.path.join(self.run_directory, 'stunnel.pid')
    stunnel_conf = dict(
        pid_file=pid_file,
        log=log,
431
        cert = certificate,
432 433 434
        key = key,
        ca_crl = ca_crl,
        ca_path = ca_path,
435
        entry_str=''
436
    )
437 438 439 440 441 442 443 444
    entry_list = []
    for name, parameter_dict in service_dict.iteritems():
      parameter_dict["name"] = name
      entry_str = self.substituteTemplate(template_entry_filename,
          parameter_dict)
      entry_list.append(entry_str)

    stunnel_conf["entry_str"] = "\n".join(entry_list)
445 446 447 448 449 450 451
    stunnel_conf_path = self.createConfigurationFile("stunnel.conf",
        self.substituteTemplate(template_filename,
          stunnel_conf))
    wrapper = zc.buildout.easy_install.scripts([('stunnel',
      'slapos.recipe.librecipe.execute', 'execute_wait')], self.ws,
      sys.executable, self.wrapper_directory, arguments=[
        [self.options['stunnel_binary'].strip(), stunnel_conf_path],
452
        [certificate, key]]
453 454 455 456
      )[0]
    self.path_list.append(wrapper)
    return stunnel_conf

457 458
  def installFrontendApache(self, ip_list, key, certificate, name,
                            port, plain_http_port=8080, 
459
                            rewrite_rule_list=[], rewrite_rule_zope_list=[],
460
                            access_control_string=None):
461 462 463 464 465 466 467 468 469
    # Create htdocs, populate it with default 404 document
    htdocs_location = os.path.join(self.data_root_directory, 'htdocs')
    self._createDirectory(htdocs_location)
    notfound_file_location = os.path.join(htdocs_location, 'notfound.html')
    notfound_template_file_location = self.getTemplateFilename(
        'notfound.html')
    notfound_file_content = open(notfound_template_file_location, 'r').read()
    self._writeFile(notfound_file_location, notfound_file_content)

470 471 472 473 474 475 476
    # Create mod_ssl cache directory
    cache_directory_location = os.path.join(self.var_directory, 'cache')
    mod_ssl_cache_location = os.path.join(cache_directory_location,
        'httpd_mod_ssl')
    self._createDirectory(cache_directory_location)
    self._createDirectory(mod_ssl_cache_location)

477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
    # Create "custom" apache configuration file if it does not exist.
    # Note : This file won't be erased or changed when slapgrid is ran.
    # It can be freely customized by node admin.
    custom_apache_configuration_directory = os.path.join(
        self.data_root_directory, 'apache-conf.d')
    self._createDirectory(custom_apache_configuration_directory)
    custom_apache_configuration_file_location = os.path.join(
        custom_apache_configuration_directory, 'apache_frontend.custom.conf')
    f = open(custom_apache_configuration_file_location, 'a')
    f.close()

    # Create backup of custom apache configuration
    backup_path = self.createBackupDirectory('custom_apache_conf_backup')
    backup_cron = os.path.join(self.cron_d, 'custom_apache_conf_backup')
    open(backup_cron, 'w').write(
        '''0 0 * * * %(rdiff_backup)s %(source)s %(destination)s'''%dict(
          rdiff_backup=self.options['rdiff_backup_binary'],
          source=custom_apache_configuration_directory,
          destination=backup_path))
    self.path_list.append(backup_cron)

498
    # Create configuration file and rewritemaps
499
    apachemap_name = "apachemap.txt"
500
    apachemapzope_name = "apachemapzope.txt"
501
    self.createConfigurationFile(apachemap_name, "\n".join(rewrite_rule_list))
502 503
    self.createConfigurationFile(apachemapzope_name,
        "\n".join(rewrite_rule_zope_list))
504
    apache_conf = self._getApacheConfigurationDict(name, ip_list, port)
505 506
    apache_conf['ssl_snippet'] = self.substituteTemplate(
        self.getTemplateFilename('apache.ssl-snippet.conf.in'),
507 508 509 510 511
        dict(login_certificate=certificate,
            login_key=key,
            httpd_mod_ssl_cache_directory=mod_ssl_cache_location,
        )
    )
512

513 514 515 516 517
    apache_conf["listen"] = "\n".join([
        "Listen %s:%s" % (ip, port)
        for port in (plain_http_port, port)
        for ip in ip_list
    ])
518

519 520 521
    path = self.substituteTemplate(
        self.getTemplateFilename('apache.conf.path-protected.in'),
        dict(path='/', access_control_string='none'))
522 523 524

    apache_conf.update(**dict(
      path_enable=path,
525
      apachemap_path=os.path.join(self.etc_directory, apachemap_name),
526
      apachemapzope_path=os.path.join(self.etc_directory, apachemapzope_name),
527
      apache_domain=name,
528 529
      https_port=port,
      plain_http_port=plain_http_port,
530
      custom_apache_conf=custom_apache_configuration_file_location,
531 532
    ))

533 534 535
    apache_conf_string = self.substituteTemplate(
          self.getTemplateFilename('apache.conf.in'), apache_conf)

536
    apache_config_file = self.createConfigurationFile('apache_frontend.conf',
537 538
        apache_conf_string)
    self.path_list.append(apache_config_file)
539

540
    self.path_list.extend(zc.buildout.easy_install.scripts([(
541
      'frontend_apache', 'slapos.recipe.erp5.apache', 'runApache')], self.ws,
542 543 544 545
          sys.executable, self.wrapper_directory, arguments=[
            dict(
              required_path_list=[key, certificate],
              binary=self.options['httpd_binary'],
546
              config=apache_config_file)
547
          ]))
548

549
    return dict(site_url="https://%s:%s/" % (name, port))