Make ERP5 SR able to deploy an ERP5 cluster.
[slapos.git] / stack / erp5 / instance-cluster-zope.cfg.in
1 {% if slap_software_type == software_type -%}
2 {% set use_ipv6 = parameter_dict.get('use-ipv6', False) -%}
3 {% set next_port = slapparameter_dict['port-base'] -%}
4 {% set site_id = slapparameter_dict['site-id'] -%}
5 {% set storage_type = slapparameter_dict['zodb-storage-type'] -%}
6 {% set part_list = [] -%}
7 {% set publish_list = [] -%}
8 {% set zodb_dict = slapparameter_dict['zodb-dict'] -%}
9 {% set longrequest_logger_base_path = buildout_directory ~ '/var/log/longrequest_logger_' -%}
10 {% macro section(name) %}{% do part_list.append(name) %}{{ name }}{% endmacro -%}
11 {% set bin_directory = parameter_dict['buildout-bin-directory'] -%}
12 {#
13 XXX: This template only supports exactly one IPv4 and one IPv6 per
14 partition. No more (undefined result), no less (IndexError).
15 -#}
16 {% set ipv4 = (ipv4_set | list)[0] -%}
17
18 [directory]
19 recipe = slapos.cookbook:mkdirectory
20 bin = ${buildout:directory}/bin
21 etc = ${buildout:directory}/etc
22 instance = ${:srv}/erp5shared
23 instance-constraint = ${:instance}/Constraint
24 instance-document = ${:instance}/Document
25 instance-etc = ${:instance}/etc
26 instance-etc-package-include = ${:instance}/etc/package-include
27 instance-extensions = ${:instance}/Extensions
28 instance-import = ${:instance}/import
29 instance-lib = ${:instance}/lib
30 instance-products = ${:instance}/Products
31 instance-propertysheet = ${:instance}/PropertySheet
32 instance-tests = ${:instance}/tests
33 log = ${:var}/log
34 run = ${:var}/run
35 services = ${:etc}/run
36 srv = ${buildout:directory}/srv
37 tmp = ${buildout:directory}/tmp
38 var = ${buildout:directory}/var
39 promises = ${:etc}/promise
40
41 [binary-link]
42 recipe = slapos.cookbook:symbolic.link
43 target-directory = ${directory:bin}
44 link-binary =
45   {{ parameter_dict['coreutils'] }}/bin/basename
46   {{ parameter_dict['coreutils'] }}/bin/cat
47   {{ parameter_dict['coreutils'] }}/bin/cp
48   {{ parameter_dict['coreutils'] }}/bin/ls
49   {{ parameter_dict['coreutils'] }}/bin/tr
50   {{ parameter_dict['coreutils'] }}/bin/uname
51   {{ parameter_dict['git'] }}/bin/git
52   {{ parameter_dict['graphviz'] }}/bin/dot
53   {{ parameter_dict['grep'] }}/bin/grep
54   {{ parameter_dict['imagemagick'] }}/bin/convert
55   {{ parameter_dict['imagemagick'] }}/bin/identify
56   {{ parameter_dict['sed'] }}/bin/sed
57   {{ parameter_dict['tesseract'] }}/bin/tesseract
58   {{ parameter_dict['w3m'] }}/bin/w3m
59   {{ parameter_dict['openssl'] }}/bin/openssl
60   {{ parameter_dict['poppler'] }}/bin/pdfinfo
61   {{ parameter_dict['poppler'] }}/bin/pdftotext
62   {{ parameter_dict['poppler'] }}/bin/pdftohtml
63   {{ parameter_dict['dmtx-utils'] }}/bin/dmtxwrite
64
65 [certificate-authority-common]
66 requests-directory = ${directory:requests}
67 ca-dir = ${directory:ca-dir}
68 ca-private = ${directory:private}
69 ca-certs = ${directory:certs}
70 ca-newcerts = ${directory:newcerts}
71 ca-crl = ${directory:crl}
72
73 [certificate-authority]
74 < = certificate-authority-common
75 recipe = slapos.cookbook:certificate_authority
76 openssl-binary = {{ parameter_dict['openssl'] }}/bin/openssl
77 wrapper = ${directory:services}/ca
78
79 {% if use_ipv6 -%}
80 {%   set ipv6 = (ipv6_set | list)[0] -%}
81 [zeo-tunnel-base]
82 recipe = slapos.cookbook:ipv4toipv6
83 runner-path = ${directory:services}/${:base-name}
84 6tunnel-path = {{ parameter_dict['6tunnel'] }}/bin/6tunnel
85 shell-path = {{ parameter_dict['dash'] }}/bin/dash
86 ipv4 = {{ ipv4 }}
87
88 {%   if storage_type == 'zeoclient' -%}
89 {#     ZEO needs tunelling for IPv6 (...until next version becomes current in Zope) -#}
90 {%     set zeo_tunneling_dict = {} -%}
91 {%     for _, _, storage_dict in zodb_dict.values() -%}
92 {%       set storage_server = storage_dict['server'] -%}
93 {%       if storage_server not in zeo_tunneling_dict -%}
94 {%         set current_port = next_port + (zeo_tunneling_dict | length) -%}
95 {%         do zeo_tunneling_dict.__setitem__(storage_server, current_port) -%}
96 [{{ section('zeo-tunnel-' ~ current_port) }}]
97 < = zeo-tunnel-base
98 base-name = {{ 'zeo-tunnel-' ~ current_port }}
99 ipv4-port = {{ current_port }}
100 ipv6-port = {{ storage_server.split(']:')[1] }}
101 ipv6 = {{ storage_server.split(']:')[0][1:] }}
102 {%       endif -%}
103 {%       do storage_dict.__setitem__('server', '' ~ ipv4 ~ ':' ~ zeo_tunneling_dict[storage_server]) -%}
104 {%     endfor -%}
105 {%     set next_port = next_port + (zeo_tunneling_dict | length) -%}
106 {%   endif -%}
107 {%   if slapparameter_dict.get('tidstorage-ip') -%}
108 [tidstorage-tunnel]
109 < = zeo-tunnel-base
110 base-name = {{ 'tidstorage-tunnel' }}
111 ipv4-port = {{ next_port }}
112 ipv6 = {{ slapparameter_dict.get('tidstorage-ip') }}
113 ipv6-port = {{ slapparameter_dict.get('tidstorage-port') }}
114 {%     do slapparameter_dict.__setitem__('tidstorage-ip', ipv4) -%}
115 {%     do slapparameter_dict.__setitem__('tidstorage-port', next_port) -%}
116 {%     set next_port = next_port + 1 -%}
117
118 [{{ section("promise-tidstorage-tunnel") }}]
119 recipe = slapos.cookbook:check_port_listening
120 hostname = ${tidstorage-tunnel:ipv4}
121 port = ${tidstorage-tunnel:ipv4-port}
122 path = ${directory:promises}/tidstorage
123 {%   endif -%}
124
125 [ipv6toipv4-base]
126 recipe = slapos.cookbook:ipv6toipv4
127 runner-path = ${directory:services}/${:base-name}
128 6tunnel-path = {{ parameter_dict['6tunnel'] }}/bin/6tunnel
129 shell-path = {{ parameter_dict['dash'] }}/bin/dash
130 ipv4 = {{ ipv4 }}
131 ipv6 = {{ ipv6 }}
132 {% endif -%}
133
134 {% if slapparameter_dict.get('tidstorage-ip') -%}
135 [tidstorage]
136 ipv4 = {{ slapparameter_dict['tidstorage-ip'] }}
137 ipv4-port = {{ slapparameter_dict['tidstorage-port'] }}
138 {% else -%}
139 [tidstorage]
140 ipv4 =
141 ipv4-port =
142 {% endif -%}
143
144 [zope-base]
145 recipe = slapos.cookbook:generic.zope.zeo.client
146 user = zope
147 ip = {{ ipv4 }}
148 timezone = {{ slapparameter_dict['timezone'] }}
149 tidstorage-ip = ${tidstorage:ipv4}
150 tidstorage-port = ${tidstorage:ipv4-port}
151 instance-etc = ${directory:instance-etc}
152 bt5-repository = ${directory:var}/bt5_repository
153 tmp-path = ${directory:tmp}
154 bin-path = ${directory:bin}
155 site-zcml = ${:instance-etc}/site.zcml
156 inituser = ${directory:instance}/inituser
157 runzope-binary = {{ bin_directory }}/runzope
158 bt5-repository-list =
159
160 [deadlock-debugger-password]
161 recipe = slapos.cookbook:pwgen.stable
162
163 [zope-conf-parameter-base]
164 ip = {{ ipv4 }}
165 site-id = {{ site_id }}
166 {% set zodb_list = [] -%}
167 {% for key, (mount_point, cache_size, storage_dict) in zodb_dict.items() -%}
168 {%   do zodb_list.append([key, mount_point, cache_size, storage_type, storage_dict]) -%}
169 {% endfor -%}
170 zodb-list = {{ dumps(zodb_list) }}
171
172 [zope-conf-base]
173 recipe = slapos.recipe.template:jinja2
174 template = {{ parameter_dict['zope-conf-template'] }}
175 extra-context =
176 context =
177   key instance directory:instance
178   key instance_products directory:instance-products
179   raw deadlock_path /manage_debug_threads
180   key deadlock_debugger_password deadlock-debugger-password:password
181   key tidstorage_ip tidstorage:ipv4
182   key tidstorage_port tidstorage:ipv4-port
183   key promise_path erp5-promise:promise-path
184   ${:extra-context}
185
186 [logrotate-entry-base]
187 recipe = slapos.cookbook:logrotate.d
188 logrotate-entries = ${logrotate:logrotate-entries}
189 backup = ${logrotate:backup}
190
191 {% macro zope(
192   name,
193   port,
194   thread_amount,
195   timerserver_interval,
196   longrequest_logger_timeout,
197   longrequest_logger_interval
198 ) -%}
199 {% set conf_name = name ~ '-conf' -%}
200 {% set conf_parameter_name = conf_name ~ '-param' -%}
201 {% set zope_tunnel_section_name = name ~ '-ipv6toipv4' -%}
202 {% set zope_tunnel_base_name = zope_tunnel_section_name -%}
203 [{{ conf_parameter_name }}]
204 < = zope-conf-parameter-base
205 pid-file = ${directory:run}/{{ name }}.pid
206 lock-file = ${directory:run}/{{ name }}.lock
207 port = {{ port }}
208 thread-amount = {{ thread_amount }}
209 timerserver-interval = {{ dumps(timerserver_interval) }}
210 event-log = ${directory:log}/{{ name }}-event.log
211 z2-log = ${directory:log}/{{ name }}-Z2.log
212
213 [{{ conf_name }}]
214 < = zope-conf-base
215 rendered = ${directory:etc}/{{ name }}.conf
216 extra-context =
217   section parameter_dict {{ conf_parameter_name }}
218
219 [{{ name }}]
220 < = zope-base
221 {% if longrequest_logger_interval < 0 -%}
222 longrequest-logger-file =
223 longrequest-logger-timeout =
224 longrequest-logger-interval =
225 {% else -%}
226 longrequest-logger-file = {{ longrequest_logger_base_path ~ name ~ ".log" }}
227 longrequest-logger-timeout = {{ dumps(longrequest_logger_timeout) }}
228 longrequest-logger-interval = {{ dumps(longrequest_logger_interval) }}
229 {% endif -%}
230 wrapper = ${directory:services}/{{ name }}
231 configuration-file = {{ '${' ~ conf_name ~ ':rendered}' }}
232 port = {{ '${' ~ conf_parameter_name ~ ':port}' }}
233
234 [{{ section("promise-" ~ name) }}]
235 recipe = slapos.cookbook:check_port_listening
236 hostname = {{ '${' ~ name ~ ':ip}' }}
237 port = {{ '${' ~ name ~ ':port}' }}
238 path = ${directory:promises}/{{ name }}
239
240 {% if use_ipv6 -%}
241 [{{ zope_tunnel_section_name }}]
242 < = ipv6toipv4-base
243 base-name = {{ zope_tunnel_base_name }}
244 ipv6-port = {{ port }}
245 ipv4-port = {{ port }}
246 {%   do publish_list.append("[" ~ ipv6 ~ "]:" ~ port) -%}
247
248 [{{ section("promise-tunnel-" ~ name) }}]
249 recipe = slapos.cookbook:check_port_listening
250 hostname = {{ '${' ~ zope_tunnel_section_name ~ ':ipv6}' }}
251 port = {{ '${' ~ zope_tunnel_section_name ~ ':ipv6-port}' }}
252 path = ${directory:promises}/{{ zope_tunnel_base_name }}
253 {% else -%}
254 {%   do publish_list.append(ipv4 ~ ":" ~ port) -%}
255 {% endif -%}
256
257 [{{ section('logrotate-entry-' ~ name) }}]
258 < = logrotate-entry-base
259 name = {{ name }}
260 log = {{ '${' ~ conf_parameter_name ~ ':event-log}' }} {{ '${' ~ conf_parameter_name ~ ':z2-log}' }} {{ '${' ~ name ~ ':longrequest-logger-file}' }}
261 post = {{ bin_directory }}/killpidfromfile {{ '${' ~ conf_parameter_name ~ ':pid-file}' }} SIGUSR2
262 {% endmacro -%}
263
264 {% for i in range(slapparameter_dict.get('instance-count', 1)) -%}
265 {{   zope("zope-" ~ i, next_port, slapparameter_dict['thread-amount'], slapparameter_dict['timerserver-interval'], slapparameter_dict['longrequest-logger-timeout'], slapparameter_dict['longrequest-logger-interval']) }}
266 {%   set next_port = next_port + 1 -%}
267 {% endfor -%}
268
269 [publish-zope]
270 recipe = slapos.cookbook:publish.serialised
271 zope-address-list = {{ dumps(publish_list) }}
272
273 [erp5-promise]
274 recipe = slapos.cookbook:erp5.promise
275 promise-path = ${directory:etc}/erp5promise.cfg
276 kumofs-url = {{ slapparameter_dict['kumofs-url'] }}
277 memcached-url = {{ slapparameter_dict['memcached-url'] }}
278 cloudooo-url = {{ slapparameter_dict['cloudooo-url'] }}
279 smtp-url = {{ slapparameter_dict['smtp-url'] }}
280 bt5 = {{ slapparameter_dict['bt5'] }}
281 bt5-repository-url = {{ slapparameter_dict['bt5-repository-url'] }}
282
283 [buildout]
284 eggs-directory = {{ eggs_directory }}
285 develop-eggs-directory = {{ develop_eggs_directory }}
286 offline = true
287 extends =
288   {{ parameter_dict['instance-logrotate-cfg'] }}
289 parts +=
290   binary-link
291   erp5-promise
292   {{ part_list | join('\n  ') }}
293   publish-zope
294 {% endif %}