Commit 7984b871 authored by Vincent Pelletier's avatar Vincent Pelletier

haproxy supports more than one listening port. Support it in recipe too.

parent 037ef82c
...@@ -66,40 +66,53 @@ class Recipe(GenericBaseRecipe): ...@@ -66,40 +66,53 @@ class Recipe(GenericBaseRecipe):
# stick in other nodes and are not coming back. Please note this option # stick in other nodes and are not coming back. Please note this option
# is not an issue if you have more than (maxqueue * node_quantity) requests # is not an issue if you have more than (maxqueue * node_quantity) requests
# because haproxy will handle a top-level queue # because haproxy will handle a top-level queue
try:
snippet_filename = self.getTemplateFilename( backend_dict = self.options['backend-dict']
'haproxy-server-snippet.cfg.in') except KeyError:
# Prepare all filestorages
server_snippet = ""
i = 0
name = self.options['name']
backend_list = self.options['backend-list'] backend_list = self.options['backend-list']
if isinstance(backend_list, str): if isinstance(backend_list, str):
# BBB # BBB
backend_list = backend_list.split() backend_list = backend_list.split()
backend_dict = {
self.options['name']: (self.options['port'], backend_list),
}
server_snippet_filename = self.getTemplateFilename(
'haproxy-server-snippet.cfg.in')
listen_snippet_filename = self.getTemplateFilename(
'haproxy-listen-snippet.cfg.in')
server_snippet = ""
ip = self.options['ip']
server_check_path = self.options['server-check-path']
# FIXME: maxconn must be provided per-backend, not globally
maxconn = self.options['maxconn']
i = 0
for name, (port, backend_list) in backend_dict.iteritems():
server_snippet += self.substituteTemplate(
listen_snippet_filename, {
'name': name,
'ip': ip,
'port': port,
'server_check_path': server_check_path,
})
for address in backend_list: for address in backend_list:
i += 1 i += 1
server_snippet += self.substituteTemplate( server_snippet += self.substituteTemplate(
snippet_filename, dict( server_snippet_filename, {
name='%s_%s' % (name, i), 'name': '%s_%s' % (name, i),
address=address, 'address': address,
cluster_zope_thread_amount=self.options['maxconn'])) 'cluster_zope_thread_amount': maxconn,
})
config = dict(
name=name,
ip=self.options['ip'],
port=self.options['port'],
server_text=server_snippet,
server_check_path=self.options['server-check-path'],)
template_filename = self.getTemplateFilename('haproxy.cfg.in')
configuration_path = self.createFile( configuration_path = self.createFile(
self.options['conf-path'], self.options['conf-path'],
self.substituteTemplate(template_filename, config)) self.substituteTemplate(
self.getTemplateFilename('haproxy.cfg.in'),
# Create running wrapper {'server_text': server_snippet},
)
)
wrapper_path = self.createPythonScript( wrapper_path = self.createPythonScript(
self.options['wrapper-path'], self.options['wrapper-path'],
'slapos.recipe.librecipe.execute.execute', 'slapos.recipe.librecipe.execute.execute',
arguments=[self.options['binary-path'].strip(), '-f', configuration_path],) arguments=[self.options['binary-path'].strip(), '-f', configuration_path],)
return [configuration_path, wrapper_path] return [configuration_path, wrapper_path]
listen %(name)s %(ip)s:%(port)s
cookie SERVERID insert
balance roundrobin
option httpchk GET %(server_check_path)s
stats uri /haproxy
stats realm Global\ statistics
server %(name)s %(address)s cookie %(name)s check inter 3s rise 1 fall 2 maxqueue 5 maxconn %(cluster_zope_thread_amount)s server %(name)s %(address)s cookie %(name)s check inter 3s rise 1 fall 2 maxqueue 5 maxconn %(cluster_zope_thread_amount)s
...@@ -29,13 +29,4 @@ defaults ...@@ -29,13 +29,4 @@ defaults
# to render a page # to render a page
option forceclose option forceclose
listen %(name)s %(ip)s:%(port)s
cookie SERVERID insert
balance roundrobin
%(server_text)s %(server_text)s
option httpchk GET %(server_check_path)s
stats uri /haproxy
stats realm Global\ statistics
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