[erp5:cluster] Make it easier to use tidstorage-dict parameter.
[slapos.git] / stack / erp5 / instance-zeo.cfg.in
1 {% if software_type == slap_software_type -%}
2 {% set use_ipv6 = slapparameter_dict.get('use-ipv6', False) -%}
3 {% set next_port = 2000 -%}
4 {% set part_list = [] -%}
5 {% set storage_dict = {} -%}
6 {% set zodb_dict = {} -%}
7 {% set tidstorage_dict = slapparameter_dict.get('tidstorage-dict') -%}
8 {% set known_tid_storage_identifier_dict = {} -%}
9 {% set default_zodb_path = buildout_directory ~ '/srv/zodb' -%}
10 {% set zodb_backup_path = buildout_directory ~ '/srv/backup/zodb' -%}
11 {% set default_tidstorage_timestamp_path = buildout_directory ~ '/srv/backup/tidstorage' -%}
12 {% macro section(name) %}{% do part_list.append(name) %}{{ name }}{% endmacro -%}
13 {#
14 XXX: This template only supports exactly one IPv6 per
15 partition. No more (undefined result), no less (IndexError).
16 -#}
17 {% set ipv4 = (ipv4_set | list)[0] -%}
18 {% set tidstorage_ip = ipv4 -%}
19 {% set tidstorage_port = 6001 -%}
20 {% set bin_directory = parameter_dict['buildout-bin-directory'] -%}
21
22 [zeo-base]
23 recipe = slapos.cookbook:zeo
24 log-path = ${directory:log}/${:base-name}.log
25 pid-path = ${directory:run}/${:base-name}.pid
26 conf-path = ${directory:etc}/${:base-name}.conf
27 wrapper-path = ${directory:services}/${:base-name}
28 binary-path = {{ bin_directory }}/runzeo
29 ip = {{ ipv4 }}
30
31 {% if use_ipv6 -%}
32 {% set ipv6 = (ipv6_set | list)[0] -%}
33 [ipv6toipv4-base]
34 recipe = slapos.cookbook:ipv6toipv4
35 runner-path = ${directory:services}/${:base-name}
36 6tunnel-path = {{ parameter_dict['6tunnel'] }}/bin/6tunnel
37 shell-path = {{ parameter_dict['dash'] }}/bin/dash
38 ipv4 = {{ ipv4 }}
39 ipv6 = {{ ipv6 }}
40 {% endif -%}
41
42 {% for export_id, mountpoint_dict in slapparameter_dict['zodb-dict'].items() -%}
43 {%   do storage_dict.setdefault(
44        mountpoint_dict.get('storage-family', 'default'), []
45      ).append((
46        export_id,
47        mountpoint_dict.get('mount-point', '/'),
48        mountpoint_dict.get('cache-size', -1),
49        mountpoint_dict.get('storage-dict', {}),
50      )) -%}
51 {% endfor -%}
52 {% for storage_family, export_list in storage_dict.items() -%}
53 {%   set known_tid_storage_identifier_host = (ipv4, local_current_port) -%}
54 {%   set client_dict = {} -%}
55 {%   for export_id, mount_point, cache_size, storage_dict in export_list -%}
56 {%     do storage_dict.__setitem__('path', storage_dict.get('path', '%(zodb)s/' ~ export_id ~ '.fs') % {'zodb': default_zodb_path}) -%}
57 {%     do client_dict.update(storage_dict.get('client', {})) -%}
58 {%     do client_dict.__setitem__('storage', export_id) -%}
59 {#     XXX: I would like to raise if export_id is present in zodb_dict -#}
60 {%     do zodb_dict.__setitem__(export_id, [
61          mount_point,
62          cache_size,
63          client_dict,
64        ]) -%}
65 {%     if tidstorage_dict is not None -%}
66 {%       do known_tid_storage_identifier_dict.__setitem__(
67            (known_tid_storage_identifier_host, export_id), (
68              storage_dict['path'],
69              tidstorage_dict.get('zodb-dict', {}).get(export_id, '%(backup)s/' ~ export_id) % {'backup': zodb_backup_path},
70              mount_point,
71            ),
72          ) -%}
73 {%     endif -%}
74 {%   endfor -%}
75 {%   set zeo_section_name = 'zeo-' ~ storage_family %}
76 [{{ zeo_section_name }}]
77 < = zeo-base
78 base-name = zeo-{{ storage_family }}
79 port = {{ next_port }}
80 {%   set storage_list = [] -%}
81 {%   for storage_name, _, _, storage_dict in export_list -%}
82 {%     do storage_list.append((storage_name, storage_dict['path'])) -%}
83 {%   endfor -%}
84 storage = {{ dumps(storage_list) }}
85
86 [{{ section(zeo_section_name ~ "-promise") }}]
87 recipe = slapos.cookbook:check_port_listening
88 hostname = {{ "${" ~ zeo_section_name ~ ":ip}" }}
89 port = {{ next_port }}
90 path = ${directory:promises}/zeo-{{ storage_family }}
91
92 {%   if use_ipv6 -%}
93 {%     do client_dict.__setitem__('server', '[' ~ ipv6 ~ ']:' ~ next_port) -%}
94 {%     set tunnel_section_name = zeo_section_name ~ "-tunnel" -%}
95 [{{ tunnel_section_name }}]
96 < = ipv6toipv4-base
97 base-name = zeo-tunnel-{{ storage_family }}
98 ipv6-port = {{ next_port }}
99 ipv4-port = {{ next_port }}
100
101 [{{ section(tunnel_section_name ~ "-promise") }}]
102 recipe = slapos.cookbook:check_port_listening
103 hostname = {{ "${" ~ tunnel_section_name ~ ":ipv6}" }}
104 port = {{ next_port }}
105 path = ${directory:promises}/zeo-tunnel-{{ storage_family }}
106 {%   else -%}
107 {%     do client_dict.__setitem__('server', ipv4 ~ ':' ~ next_port) -%}
108 {%   endif -%}
109 {%   set next_port = next_port + 1 -%}
110 {% endfor -%}
111
112 {% if tidstorage_dict is not None -%}
113 [tidstorage]
114 recipe = slapos.cookbook:tidstorage
115 known-tid-storage-identifier-dict = {{ dumps(known_tid_storage_identifier_dict) }}
116 configuration-path = ${directory:etc}/tidstorage.py
117 ip = {{ tidstorage_ip }}
118 port = {{ tidstorage_port }}
119 timestamp-file-path = {{ tidstorage_dict.get('timestamp-path', '%(backup)s/repozo_tidstorage_timestamp.log' % {'backup': default_tidstorage_timestamp_path}) }}
120 logfile-name = ${directory:log}/tidstorage.log
121 pidfile-name = ${directory:run}/tidstorage.pid
122 status-file = ${directory:tidstorage}/tidstorage.tid
123 tidstorage-repozo-binary = {{ bin_directory }}/tidstorage_repozo
124 tidstoraged-binary = {{ bin_directory }}/tidstoraged
125 repozo-binary = {{ bin_directory }}/repozo
126 tidstorage-wrapper = ${directory:services}/tidstoraged
127 repozo-wrapper = ${buildout:bin-directory}/tidstorage-repozo
128
129 [{{ section("promise-tidstorage") }}]
130 recipe = slapos.cookbook:check_port_listening
131 hostname = ${tidstorage:ip}
132 port = ${tidstorage:port}
133 path = ${directory:promises}/tidstorage
134
135 {%  if use_ipv6 -%}
136 [tidstorage-tunnel]
137 < = ipv6toipv4-base
138 base-name = tidstorage-tunnel
139 ipv4-port = ${tidstorage:port}
140 ipv6-port = ${tidstorage:port}
141
142 [{{ section("promise-tidstorage-tunnel") }}]
143 recipe = slapos.cookbook:check_port_listening
144 hostname = ${tidstorage-tunnel:ipv6}
145 port = ${tidstorage-tunnel:ipv6-port}
146 path = ${directory:promises}/tidstorage
147 {% endif -%}
148
149 [{{ section("cron-entry-tidstorage-backup") }}]
150 # TODO:
151 # - configurable periodicity
152 # - configurable full/incremental
153 # - configurable retention
154 recipe = slapos.cookbook:cron.d
155 cron-entries = ${cron:cron-entries}
156 name = tidstorage
157 frequency = 0 0 * * *
158 command = ${tidstorage:repozo-wrapper}
159
160 [{{ section("logrotate-tidstorage") }}]
161 recipe = slapos.cookbook:logrotate.d
162 logrotate-entries = ${logrotate:logrotate-entries}
163 backup = ${logrotate:backup}
164 name = tidstorage
165 log = ${tidstorage:logfile-name}
166 post = {{ bin_directory }}/killpidfromfile ${tidstorage:pidfile-name} SIGHUP
167 {% else -%}
168 [tidstorage]
169 ip =
170 port =
171
172 [tidstorage-tunnel]
173 ipv6 =
174 ipv6-port =
175 {% endif -%}
176
177 [publish]
178 recipe = slapos.cookbook:publish.serialised
179 zodb-storage-type = zeoclient
180 zodb-dict = {{ dumps(zodb_dict) }}
181 {% if use_ipv6 -%}
182 tidstorage-ip = ${tidstorage-tunnel:ipv6}
183 tidstorage-port = ${tidstorage-tunnel:ipv6-port}
184 {% else -%}
185 tidstorage-ip = ${tidstorage:ip}
186 tidstorage-port = ${tidstorage:port}
187 {% endif -%}
188
189 [directory]
190 recipe = slapos.cookbook:mkdirectory
191 etc = ${buildout:directory}/etc
192 services = ${:etc}/run
193 promises = ${:etc}/promise
194 var = ${buildout:directory}/var
195 log = ${:var}/log
196 run = ${:var}/run
197 backup-zodb = {{ zodb_backup_path }}
198 zodb = {{ default_zodb_path }}
199 tidstorage = {{ default_tidstorage_timestamp_path }}
200
201 [buildout]
202 extends =
203   {{ parameter_dict['instance-logrotate-cfg'] }}
204 parts +=
205   {{ part_list | join('\n  ') }}
206   publish
207 eggs-directory = {{ eggs_directory }}
208 develop-eggs-directory = {{ develop_eggs_directory }}
209 offline = true
210
211 {% endif %}