instance-neo-storage-mysql.cfg.in 4.65 KB
Newer Older
1 2 3
{% macro section(name) %}{% do part_list.append(name) %}{{ name }}{% endmacro -%}
{% set part_list = [] -%}
{% set init_list = [] -%}
Vincent Pelletier's avatar
Vincent Pelletier committed
4

5 6 7 8 9
[mysqld]
recipe = slapos.cookbook:generic.mysql.wrap_mysqld
output = ${directory:etc_run}/mariadb
binary = ${:mysql-base-directory}/bin/mysqld
configuration-file = ${my-cnf:rendered}
Vincent Pelletier's avatar
Vincent Pelletier committed
10
data-directory = ${directory:srv_mariadb}
11 12 13 14
mysql-install-binary = ${:mysql-base-directory}/scripts/mysql_install_db
mysql-base-directory = {{ mariadb_location }}

[my-cnf-parameters]
Vincent Pelletier's avatar
Vincent Pelletier committed
15
socket = ${directory:var_run}/mariadb.sock
16
data-directory = ${mysqld:data-directory}
17
tmp-directory = ${directory:tmp}
18
pid-file = ${directory:var_run}/mariadb.pid
Vincent Pelletier's avatar
Vincent Pelletier committed
19 20
error-log = ${directory:log}/mariadb_error.log
slow-query-log = ${directory:log}/mariadb_slowquery.log
21
extra-dict = {{ dumps(slapparameter_dict.get('mysql', {})) }}
22
init-file = ${init-script:rendered}
Vincent Pelletier's avatar
Vincent Pelletier committed
23

24 25
[my-cnf]
recipe = slapos.recipe.template:jinja2
26
extensions = jinja2.ext.do
27
rendered = ${directory:etc}/mariadb.cnf
28
template = {{ template_neo_my_cnf }}
29
context = section parameter_dict my-cnf-parameters
Vincent Pelletier's avatar
Vincent Pelletier committed
30

31 32 33
{% set master_list = [] -%}
{% set admin_list = [] -%}
{% for k, v in slapparameter_dict.iteritems() -%}
34
{%   if k.startswith('master-') and v -%}
35 36
{%     do master_list.append(v) -%}
{%   endif -%}
37
{%   if k.startswith('admin-') and v -%}
38 39 40 41 42 43 44
{%     do admin_list.append(v) -%}
{%   endif -%}
{% endfor -%}

[publish]
recipe = slapos.cookbook:publish.serialised
# TODO: make port a partition parameter
45
ip = {{ "[%s]" % list(ipv6_set)[0] if ipv6_set else list(ipv4_set)[0] }}
46 47 48 49
{% set admin = slapparameter_dict.get('admin', 2050) -%}
{% set master = slapparameter_dict.get('master', 2051) -%}
{% if master -%}
port-master = {{ master }}
50
master = ${:ip}:${:port-master}
51 52 53 54 55
{% else -%}
master =
{% endif -%}
{% if admin -%}
port-admin = {{ admin }}
56
admin = ${:ip}:${:port-admin}
57 58 59
{% else -%}
admin =
{% endif -%}
60 61 62 63
masters = {{ ' '.join(sorted(master_list)) }}
{%- if admin_list %}
admins = {{ ' '.join(sorted(admin_list)) }}
{%- endif %}
Vincent Pelletier's avatar
Vincent Pelletier committed
64

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
{#- Hack to deploy SSL certs via instance parameters #}
{%- for name, pem in zip(('ca.crt', 'neo.crt', 'neo.key'),
                        slapparameter_dict['ssl']) %}
{%-   if pem %}

[{{ section(name) }}]
recipe = slapos.recipe.template:jinja2
rendered = ${directory:etc}/{{name}}
template = inline:{{'{{'}}pem}}
context = key pem :pem
pem = {{dumps(pem)}}
{%-   endif %}
{%- endfor %}
{#- endhack #}

Vincent Pelletier's avatar
Vincent Pelletier committed
80 81 82
[neo-storage]
recipe = slapos.cookbook:neoppod.storage
binary = {{ bin_directory }}/neostorage
83
ip = ${publish:ip}
84
ssl = {{ dumps(bool(slapparameter_dict['ssl'])) }}
85
cluster = {{ dumps(slapparameter_dict['cluster']) }}
86
masters = ${publish:masters}
Vincent Pelletier's avatar
Vincent Pelletier committed
87 88
database-adapter = MySQL
wait-database = 60
89
engine = {{ slapparameter_dict.get('engine', '') }}
Vincent Pelletier's avatar
Vincent Pelletier committed
90

91 92 93 94 95 96 97 98 99 100
{% for i in range(slapparameter_dict.get('storage-count', 1)) -%}
{%   set storage_id = 'neo-storage-' ~ i -%}
[{{ section(storage_id) }}]
< = neo-storage
wrapper = ${directory:etc_run}/{{ 'neostorage-' ~ i }}
logfile = ${directory:log}/{{ 'neostorage-' ~ i }}.log
{%   do init_list.append('CREATE DATABASE IF NOT EXISTS neo' ~  i ~ ';') -%}
database-parameters = root@neo{{ i }}${my-cnf-parameters:socket}

[{{ section('logrotate-storage-' ~ i) }}]
101
< = logrotate-entry-base
102 103 104 105 106 107 108 109 110 111 112 113
name = {{ storage_id }}
log = {{ '${' +  storage_id + ':logfile}' }}
post = {{ bin_directory }}/slapos-kill -n neostorage -s RTMIN+1 ${:log}

{% endfor -%}
[init-script]
recipe = slapos.recipe.template:jinja2
# XXX: is there a better location ?
rendered = ${directory:etc}/mariadb_initial_setup.sql
template = inline:
  {{ init_list | join('\n\t') }}

Vincent Pelletier's avatar
Vincent Pelletier committed
114
[directory]
115 116
recipe = slapos.cookbook:mkdirectory
promises = ${buildout:directory}/etc/promises
117
bin = ${buildout:directory}/bin
Vincent Pelletier's avatar
Vincent Pelletier committed
118 119 120 121 122
etc = ${buildout:directory}/etc
var = ${buildout:directory}/var
etc_run =  ${:etc}/run
var_run =  ${:var}/run
srv_mariadb = ${buildout:directory}/srv/mariadb
123
log = ${buildout:directory}/var/log
124
tmp = ${buildout:directory}/tmp
Julien Muchembled's avatar
Julien Muchembled committed
125 126

[logrotate-mysql]
127
< = logrotate-entry-base
Julien Muchembled's avatar
Julien Muchembled committed
128 129 130
name = mariadb
log = ${my-cnf-parameters:error-log} ${my-cnf-parameters:slow-query-log}
post = ${mysqld:mysql-base-directory}/bin/mysql --defaults-file="${my-cnf:rendered}" -e "FLUSH LOGS"
131

132 133 134 135 136 137 138 139 140 141 142 143 144
{% if runTestSuite_in is defined -%}
# bin/runTestSuite to run NEO tests
[{{ section('runTestSuite') }}]
recipe = slapos.recipe.template:jinja2
rendered = ${directory:bin}/${:_buildout_section_name_}
template = {{ runTestSuite_in }}
mode = 0755
context =
    section directory         directory
    section my_cnf_parameters my-cnf-parameters
    raw     bin_directory     {{ bin_directory }}
{% endif -%}

145 146 147
[buildout]
extends =
  {{ logrotate_cfg }}
148
{%- if master %}
149
  {{ master_cfg }}
150 151
{%- endif %}
{%- if admin %}
152
  {{ admin_cfg }}
153
{%- endif %}
154 155 156
parts +=
  {{ '\n  '.join(part_list) }}
  logrotate-mysql