instance-mariadb.cfg.in 9.44 KB
Newer Older
1 2 3 4
{% set part_list = [] -%}
{% macro section(name) %}{% do part_list.append(name) %}{{ name }}{% endmacro -%}
{% set use_ipv6 = slapparameter_dict.get('use-ipv6', False) -%}
{% set database_list = slapparameter_dict.get('database-list', [{'name': 'erp5', 'user': 'user', 'password': 'insecure'}]) -%}
5
{% set test_database_list = [] %}
6
{% for database_count in range(slapparameter_dict.get('test-database-amount', 1)) -%}
7
{%   do test_database_list.append({'name': 'erp5_test_' ~ database_count, 'user': 'testuser_' ~ database_count, 'password': 'testpassword' ~ database_count}) -%}
8 9 10 11
{% endfor -%}
{% set catalog_backup = slapparameter_dict.get('catalog-backup', {}) -%}
{% set full_backup_retention_days = catalog_backup.get('full-retention-days', 7) -%}
{% set incremental_backup_retention_days = catalog_backup.get('incremental-retention-days', full_backup_retention_days) -%}
12
{% set port = slapparameter_dict['tcpv4-port'] %}
13
{% if use_ipv6 -%}
14
{%   set ip = (ipv6_set | list)[0] -%}
15
{% else -%}
16
{%   set ip = (ipv4_set | list)[0] -%}
17
{% endif -%}
18 19 20 21 22 23

[publish-mariadb-url]
recipe = slapos.cookbook:publish.serialised
{% macro render_database_list(database_list) -%}
{% set publish_database_list = [] -%}
{% for database in database_list -%}
24 25
{%   if database.get('user') -%}
{%     do publish_database_list.append("mysql://" ~ database['user'] ~ ":" ~ database['password'] ~ "@" ~ ip ~ ":" ~ port ~ "/" ~ database['name']) -%}
26
{%   else -%}
27
{%     do publish_database_list.append("mysql://" ~ ip ~ ":" ~ port ~ "/" ~ database['name']) -%}
28
{%   endif -%}
29 30 31 32 33
{% endfor -%}
{{ dumps(publish_database_list) }}
{% endmacro -%}
database-list = {{ render_database_list(database_list) }}
test-database-list = {{ render_database_list(test_database_list) }}
34
monitor-url = ${publish-connection-informations:monitor_url}
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
[simplefile]
recipe = slapos.recipe.template:jinja2
template = inline:{{ '{{ content }}' }}

{% macro simplefile(section_name, file_path, content, mode='') -%}
{%   set content_section_name = section_name ~ '-content' -%}
[{{  content_section_name }}]
content = {{ dumps(content) }}

[{{  section(section_name) }}]
< = simplefile
rendered = {{ file_path }}
context = key content {{content_section_name}}:content
mode = {{ mode }}
{%- endmacro %}
{% set ssl_dict = {} -%}
{% macro sslfile(key, content, mode='644') -%}
{%   set path = '${directory:mariadb-ssl}/' ~ key ~ '.pem' -%}
{%   do ssl_dict.__setitem__(key, path) -%}
{{   simplefile('ssl-file-' ~ key, path, content, mode) }}
{%- endmacro %}
{% set ssl_parameter_dict = slapparameter_dict.get('ssl') -%}
{% if ssl_parameter_dict -%}
{%   set base_directory = '${directory:mariadb-ssl}/' -%}
{# Note: The key content will be stored in .installed.cfg, and this template's
rendering, so the only point of mode is to avoid risking mariadb complaining
about laxist file mode. -#}
{{   sslfile('key', ssl_parameter_dict['key'], mode='600') }}
{{   sslfile('crt', ssl_parameter_dict['crt']) }}
{%   if 'ca-crt' in ssl_parameter_dict -%}
{{     sslfile('ca-crt', ssl_parameter_dict['ca-crt']) }}
{%   endif -%}
68 69 70
{%   if 'crl' in ssl_parameter_dict -%}
{{     sslfile('crl', ssl_parameter_dict['crl']) }}
{%   endif -%}
71 72
{%- endif %}

73 74
{% if full_backup_retention_days > -1 -%}
[{{ section('cron-entry-mariadb-backup') }}]
75
recipe = slapos.cookbook:cron.d
76
cron-entries = ${cron:cron-entries}
77
name = mariadb-backup
78 79 80 81 82 83 84
frequency = 0 22 * * *
{# When binlogs are enabled:
# flush-logs: used so no manipulation on binlogs is needed to restore from
#   full + binlogs. The first binlog after a dump starts from dump snapshot and
#   can be fully restored.
# master-data: use value "2" as we are not in a replication case
#}
85
command = "${binary-wrap-mysqldump:wrapper-path}" -u root --all-databases --single-transaction {% if incremental_backup_retention_days > -1 %}--flush-logs --master-data=2 {% endif %}| {{ parameter_dict['gzip-location'] }}/bin/gzip > "${directory:mariadb-backup-full}/$({{ parameter_dict['coreutils-location'] }}/bin/date "+%Y%m%d%H%M%S").sql.gz"
86 87 88 89 90 91 92
{# KEEP GLOB PATTERN IN SYNC with generated filenames above
#           YYYYmmddHHMMSS -#}
file-glob = ??????????????.sql.gz

{% if full_backup_retention_days > 0 -%}
[{{ section("cron-entry-mariadb-backup-expire") }}]
recipe = slapos.cookbook:cron.d
93
cron-entries = ${cron:cron-entries}
94 95 96 97 98 99 100
name = mariadb-backup-expire
frequency = 0 22 * * *
command = {{ parameter_dict['findutils-location'] }}/bin/find "${directory:mariadb-backup-full}" -maxdepth 1 -name "${cron-entry-mariadb-backup:file-glob}" -daystart -mtime +{{ full_backup_retention_days }} -delete
{%- endif %}
{%- endif %}

[my-cnf-parameters]
101 102
ip = {{ ip }}
port = {{ port }}
103 104 105 106 107
socket = ${directory:run}/mariadb.sock
data-directory = ${directory:mariadb-data}
pid-file = ${directory:run}/mariadb.pid
error-log = ${directory:log}/mariadb_error.log
slow-query-log = ${directory:log}/mariadb_slowquery.log
108
long-query-time = {{ dumps(slapparameter_dict.get('long-query-time', 1)) }}
109
innodb-buffer-pool-size = {{ dumps(slapparameter_dict.get('innodb-buffer-pool-size', 0)) }}
110 111
innodb-log-file-size = {{ dumps(slapparameter_dict.get('innodb-log-file-size', 0)) }}
innodb-log-buffer-size = {{ dumps(slapparameter_dict.get('innodb-log-buffer-size', 0)) }}
112
relaxed-writes = {{ dumps(slapparameter_dict.get('relaxed-writes', False)) }}
113 114 115
{% if incremental_backup_retention_days > -1 -%}
binlog-path = ${directory:mariadb-backup-incremental}/binlog
# XXX: binlog rotation happens along with other log's rotation
116
binlog-expire-days = {{ dumps(incremental_backup_retention_days) }}
117 118
{% else %}
binlog-path =
119 120 121 122
{%- endif %}
{%- for key, value in ssl_dict.items() -%}
ssl-{{ key }} = {{ value }}
{% endfor %}
123 124 125 126 127 128 129 130

[my-cnf]
recipe = slapos.recipe.template:jinja2
rendered = ${directory:etc}/mariadb.cnf
template = {{ parameter_dict['template-my-cnf'] }}
context = section parameter_dict my-cnf-parameters

[init-script-parameters]
131
database-list = {{ dumps(database_list + test_database_list) }}
132 133 134 135 136 137 138 139 140 141 142 143 144 145

[init-script]
recipe = slapos.recipe.template:jinja2
# XXX: is there a better location ?
rendered = ${directory:etc}/mariadb_initial_setup.sql
template = {{ parameter_dict['template-mariadb-initial-setup'] }}
context = section parameter_dict init-script-parameters

[update-mysql]
recipe = slapos.cookbook:generic.mysql.wrap_update_mysql
output = ${directory:services}/mariadb_update
binary = ${binary-wrap-mysql_upgrade:wrapper-path}
mysql = ${binary-wrap-mysql:wrapper-path}
init-script = ${init-script:rendered}
146
mysql_tzinfo_to_sql = ${binary-wrap-mysql_tzinfo_to_sql:wrapper-path}
147 148 149 150 151 152 153 154 155

[mysqld]
recipe = slapos.cookbook:generic.mysql.wrap_mysqld
output = ${directory:services}/mariadb
binary = {{ parameter_dict['mariadb-location'] }}/bin/mysqld
configuration-file = ${my-cnf:rendered}
data-directory = ${my-cnf-parameters:data-directory}
mysql-install-binary = {{ parameter_dict['mariadb-location'] }}/scripts/mysql_install_db
mysql-base-directory = {{ parameter_dict['mariadb-location'] }}
156 157 158

[logrotate-entry-mariadb]
recipe = slapos.cookbook:logrotate.d
159 160
logrotate-entries = ${logrotate:logrotate-entries}
backup = ${logrotate:backup}
161
name = mariadb
162
log = ${my-cnf-parameters:error-log} ${my-cnf-parameters:slow-query-log}
163
post = "${binary-wrap-mysql:wrapper-path}" -B -u root -e "FLUSH LOGS"
164 165 166

[binary-link]
recipe = slapos.cookbook:symbolic.link
167
target-directory = ${directory:bin}
168
link-binary = {{ dumps(parameter_dict['link-binary']) }}
169

170 171 172 173
[{{ section("binary-link-mysqlbinlog") }}]
< = binary-link
link-binary = {{ parameter_dict['mariadb-location'] }}/bin/mysqlbinlog

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
[binary-wrap-base]
recipe = slapos.cookbook:wrapper
# Note: --defaults-file must be the first argument, otherwise wrapped binary
# will reject it.
command-line = "{{ parameter_dict['mariadb-location'] }}/bin/${:command}" --defaults-file="${my-cnf:rendered}"
wrapper-path = ${directory:bin}/${:command}
parameters-extra = true

[binary-wrap-mysql]
< = binary-wrap-base
command = mysql

[binary-wrap-mysqldump]
< = binary-wrap-base
command = mysqldump

190
[binary-wrap-mysql_upgrade]
191
< = binary-wrap-base
192 193 194 195
command = mysql_upgrade

[binary-wrap-mysql_tzinfo_to_sql]
< = binary-wrap-base
196
command-line = "{{ parameter_dict['mariadb-location'] }}/bin/${:command}"
197
command = mysql_tzinfo_to_sql
198 199 200

[directory]
recipe = slapos.cookbook:mkdirectory
201 202 203 204 205 206 207 208 209
bin = ${buildout:directory}/bin
etc = ${buildout:directory}/etc
services = ${:etc}/run
promise = ${:etc}/promise
srv = ${buildout:directory}/srv
backup = ${:srv}/backup
mariadb-backup-full = ${:backup}/mariadb-full
mariadb-backup-incremental = ${:backup}/mariadb-incremental
mariadb-data = ${:srv}/mariadb
210
mariadb-ssl = ${:etc}/mariadb-ssl
211 212 213
var = ${buildout:directory}/var
log = ${:var}/log
run = ${:var}/run
214

215
[promise]
216 217 218 219
recipe = slapos.cookbook:wrapper
command-line = "{{ parameter_dict['bin-directory'] }}/is-local-tcp-port-opened" "${my-cnf-parameters:ip}" "${my-cnf-parameters:port}"
wrapper-path = ${directory:promise}/mariadb
parameters-extra = true
220

221 222 223 224 225 226 227 228 229 230 231
[{{ section('monitor-current-log-access') }}]
< = monitor-directory-access
source = ${directory:log}

[{{ section('monitor-backup-log-access') }}]
< = monitor-directory-access
source = ${logrotate-entry-mariadb:backup}

[monitor-parameters]
port = 3380

232
[buildout]
233 234 235
extends =
  {{ logrotate_cfg }}
  {{ parameter_dict['template-monitor'] }}
236
parts +=
237 238 239 240 241 242
  publish-mariadb-url
  logrotate-entry-mariadb
  binary-link
  update-mysql
  mysqld
  promise
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

# Access to mariadb logs
  certificate-authority
  cron-entry-monitor
  cron-entry-rss
  deploy-index
  setup-static-files
  certificate-authority
  public-symlink
  cgi-httpd-wrapper
  cgi-httpd-graceful-wrapper
  monitor-promise
  monitor-instance-log-access

# Complete parts with sections
258
  {{ part_list | join('\n  ') }}