formula: galera | formula: galera | ||||
grains: | grains: | ||||
noservices: True | noservices: True | ||||
dependencies: | |||||
- name: mysql | |||||
repo: git | |||||
source: https://github.com/salt-formulas/salt-formula-mysql.git | |||||
- name: linux | |||||
repo: git | |||||
source: https://github.com/salt-formulas/salt-formula-linux.git | |||||
state_top: | state_top: | ||||
base: | base: | ||||
"*": | "*": | ||||
- galeracluster_debian_repo | - galeracluster_debian_repo | ||||
pillars-from-files: | pillars-from-files: | ||||
galeracluster_debian_repo.sls: tests/pillar/repo_galeracluster.sls | galeracluster_debian_repo.sls: tests/pillar/repo_galeracluster.sls | ||||
dependencies: | |||||
- name: mysql | |||||
repo: git | |||||
source: https://github.com/salt-formulas/salt-formula-mysql.git | |||||
dependencies: | |||||
- name: linux | |||||
repo: git | |||||
source: https://github.com/salt-formulas/salt-formula-linux.git | |||||
verifier: | verifier: | ||||
name: inspec | name: inspec |
- make test | tail | - make test | tail | ||||
script: | script: | ||||
- test ! -e .kitchen.yml || bundle exec kitchen test -t tests/integration | |||||
- bundle exec kitchen test -t tests/integration | |||||
notifications: | notifications: | ||||
webhooks: | webhooks: |
password: clustercheck | password: clustercheck | ||||
database: '*.*' | database: '*.*' | ||||
grants: PROCESS | grants: PROCESS | ||||
grant_option: False | |||||
- name: inspector | - name: inspector | ||||
host: 127.0.0.1 | host: 127.0.0.1 | ||||
password: password | password: password | ||||
mydb: | mydb: | ||||
- database: mydb | - database: mydb | ||||
- table: mytable | - table: mytable | ||||
- grant_option: False | |||||
- grant_option: True | |||||
- grants: | - grants: | ||||
- all privileges | - all privileges | ||||
Additional check params: | |||||
mysql: | |||||
server: | |||||
clustercheck: | |||||
- user: clustercheck | |||||
- password: clustercheck | |||||
- available_when_donor: 0 | |||||
- available_when_readonly: 1 | |||||
- enabled: True | |||||
- xinetd_port 9200 | |||||
Additional check params: | |||||
.. code-block:: yaml | |||||
galera: | |||||
clustercheck: | |||||
- enabled: True | |||||
- user: clustercheck | |||||
- password: clustercheck | |||||
- available_when_donor: 0 | |||||
- available_when_readonly: 1 | |||||
- port 9200 | |||||
Usage | Usage | ||||
MySQL Galera check sripts | MySQL Galera check sripts | ||||
.. code-block:: bash | .. code-block:: bash | ||||
mysql> SHOW STATUS LIKE 'wsrep%'; | mysql> SHOW STATUS LIKE 'wsrep%'; | ||||
mysql> SHOW STATUS LIKE 'wsrep_cluster_size' ;" | mysql> SHOW STATUS LIKE 'wsrep_cluster_size' ;" |
{%- from "galera/map.jinja" import clustercheck %} | |||||
{%- if clustercheck.get('enabled', False) %} | |||||
clustercheck_dir: | |||||
file.directory: | |||||
- name: /usr/local/bin/ | |||||
- user: root | |||||
- group: root | |||||
- mode: 750 | |||||
/usr/local/bin/mysql_clustercheck: | |||||
file.managed: | |||||
- source: salt://galera/files/clustercheck.sh | |||||
- user: root | |||||
- group: root | |||||
- mode: 755 | |||||
- require: | |||||
- file: clustercheck_dir | |||||
/etc/xinetd.d/mysql_clustercheck.conf: | |||||
file.managed: | |||||
- source: salt://galera/files/xinet.d.conf | |||||
- template: jinja | |||||
- defaults: | |||||
user: nobody | |||||
server: '/usr/local/bin/clustercheck {{ clustercheck.get('user', 'clustercheck') }} {{ clustercheck.get('password', 'clustercheck') }} {{ clustercheck.get('available_when_donor', 0) }} {{ clustercheck.get('available_when_readonly', 0) }}' | |||||
port: clustercheck.get('port', 9200) | |||||
flags: REUSE | |||||
per_source: UNLIMITED | |||||
- require: | |||||
- file: /usr/local/bin/mysql_clustercheck | |||||
{%- if not grains.get('noservices', False) %} | |||||
- watch_in: | |||||
- galera_xinetd_service | |||||
{%- endif %} | |||||
galera_xinetd_package: | |||||
pkg.installed: | |||||
- name: xinetd | |||||
{%- if not grains.get('noservices', False) %} | |||||
galera_xinetd_service: | |||||
service.running: | |||||
- name: xinetd | |||||
- require: | |||||
- pkg: xinetd | |||||
{%- endif %} | |||||
{%- endif %} | |||||
{%- if pillar.galera.slave is defined %} | {%- if pillar.galera.slave is defined %} | ||||
- galera.slave | - galera.slave | ||||
{%- endif %} | {%- endif %} | ||||
{%- if pillar.galera.clustercheck is defined %} | |||||
- galera.clustercheck | |||||
{%- endif %} | |||||
{%- if pillar.galera.monitor is defined %} | {%- if pillar.galera.monitor is defined %} | ||||
- galera.monitor | - galera.monitor | ||||
{%- endif %} | {%- endif %} |
'config': '/etc/mysql/my.cnf', | 'config': '/etc/mysql/my.cnf', | ||||
}, | }, | ||||
}, grain='oscodename', merge=pillar.galera.get('slave', {}))) %} | }, grain='oscodename', merge=pillar.galera.get('slave', {}))) %} | ||||
{% set clustercheck = salt['grains.filter_by']({ | |||||
'default': { | |||||
'clustercheck': { | |||||
'enabled': True, | |||||
'user': clustercheck, | |||||
'password': clustercheck, | |||||
'port': '9200' | |||||
}, | |||||
}, | |||||
}, merge=pillar.galera.get('clustercheck', {})) %} | |||||
- defaults: | - defaults: | ||||
service: {{ master|yaml }} | service: {{ master|yaml }} | ||||
- template: jinja | - template: jinja | ||||
- timeout: 1800 | |||||
galera_bootstrap_script: | galera_bootstrap_script: | ||||
file.managed: | file.managed: | ||||
- require: | - require: | ||||
- file: galera_run_dir | - file: galera_run_dir | ||||
- file: galera_init_script | - file: galera_init_script | ||||
- timeout: 1800 | |||||
galera_bootstrap_set_root_password: | galera_bootstrap_set_root_password: | ||||
cmd.run: | cmd.run: |
{%- if pillar.get('mysql', {}).server is defined %} | {%- if pillar.get('mysql', {}).server is defined %} | ||||
{%- from "mysql/map.jinja" import mysql_connection_args as connection %} | |||||
{%- set server = pillar.mysql.server %} | {%- set server = pillar.mysql.server %} | ||||
{%- for database_name, database in server.get('database', {}).iteritems() %} | {%- for database_name, database in server.get('database', {}).iteritems() %} | ||||
{%- if not grains.get('noservices', False) %} | |||||
mysql_database_{{ database_name }}: | mysql_database_{{ database_name }}: | ||||
mysql_database.present: | mysql_database.present: | ||||
- name: {{ database_name }} | - name: {{ database_name }} | ||||
- character_set: {{ database.get('encoding', 'utf8') }} | |||||
- connection_user: {{ connection.user }} | |||||
- connection_pass: {{ connection.password }} | |||||
- connection_charset: {{ connection.charset }} | |||||
{%- endif %} | |||||
{%- for user in database.users %} | {%- for user in database.users %} | ||||
{%- if not grains.get('noservices', False) %} | |||||
mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}: | mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}: | ||||
mysql_user.present: | mysql_user.present: | ||||
- host: '{{ user.host }}' | - host: '{{ user.host }}' | ||||
- name: '{{ user.name }}' | - name: '{{ user.name }}' | ||||
{%- if user.password is defined %} | |||||
- password: {{ user.password }} | - password: {{ user.password }} | ||||
{%- else %} | |||||
- allow_passwordless: true | |||||
{%- endif %} | |||||
- connection_user: {{ connection.user }} | |||||
- connection_pass: {{ connection.password }} | |||||
- connection_charset: {{ connection.charset }} | |||||
mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}: | mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}: | ||||
mysql_grants.present: | mysql_grants.present: | ||||
- database: '{{ database_name }}.*' | - database: '{{ database_name }}.*' | ||||
- user: '{{ user.name }}' | - user: '{{ user.name }}' | ||||
- host: '{{ user.host }}' | - host: '{{ user.host }}' | ||||
- connection_user: {{ connection.user }} | |||||
- connection_pass: {{ connection.password }} | |||||
- connection_charset: {{ connection.charset }} | |||||
- require: | - require: | ||||
- mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }} | - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }} | ||||
- mysql_database: mysql_database_{{ database_name }} | - mysql_database: mysql_database_{{ database_name }} | ||||
{%- endif %} | |||||
{%- endfor %} | {%- endfor %} | ||||
{%- if database.initial_data is defined %} | {%- if database.initial_data is defined %} | ||||
/root/mysql/scripts/restore_{{ database_name }}.sh: | /root/mysql/scripts/restore_{{ database_name }}.sh: | ||||
file.managed: | file.managed: | ||||
- source: salt://mysql/conf/restore.sh | - source: salt://mysql/conf/restore.sh | ||||
- cwd: /root | - cwd: /root | ||||
- require: | - require: | ||||
- file: /root/mysql/scripts/restore_{{ database_name }}.sh | - file: /root/mysql/scripts/restore_{{ database_name }}.sh | ||||
{%- endif %} | {%- endif %} | ||||
{%- endfor %} | {%- endfor %} | ||||
{%- if not grains.get('noservices', False) %} | |||||
{%- for user in server.get('users', []) %} | {%- for user in server.get('users', []) %} | ||||
{%- set user_hosts = user.get('hosts', user.get('host', 'localhost'))|sequence %} | |||||
{%- for host in user_hosts %} | |||||
{%- for host in user.get('hosts', user.get('host', 'localhost'))|sequence %} | |||||
{%- if not grains.get('noservices', False) %} | |||||
mysql_user_{{ user.name }}_{{ host }}: | mysql_user_{{ user.name }}_{{ host }}: | ||||
mysql_user.present: | mysql_user.present: | ||||
- host: '{{ user.host }}' | |||||
- host: '{{ host }}' | |||||
- name: '{{ user.name }}' | - name: '{{ user.name }}' | ||||
{%- if user['password_hash'] is defined %} | {%- if user['password_hash'] is defined %} | ||||
- password_hash: '{{ user.password_hash }}' | - password_hash: '{{ user.password_hash }}' | ||||
{%- elif user['password'] is defined and user['password'] != None %} | {%- elif user['password'] is defined and user['password'] != None %} | ||||
- password: '{{ user.password }}' | |||||
- password: '{{ user.password }}' | |||||
{%- else %} | {%- else %} | ||||
- allow_passwordless: True | - allow_passwordless: True | ||||
{%- endif %} | {%- endif %} | ||||
- connection_charset: utf8 | |||||
- connection_user: {{ connection.user }} | |||||
- connection_pass: {{ connection.password }} | |||||
- connection_charset: {{ connection.charset }} | |||||
{%- if 'grants' in user %} | {%- if 'grants' in user %} | ||||
mysql_user_{{ user.name }}_{{ host }}_grants: | mysql_user_{{ user.name }}_{{ host }}_grants: | ||||
mysql_grants.present: | mysql_grants.present: | ||||
- name: {{ user.name }} | - name: {{ user.name }} | ||||
- grant: {{ user['grants']|sequence|join(",") }} | - grant: {{ user['grants']|sequence|join(",") }} | ||||
- database: '*.*' | |||||
- database: user.get('database','*.*') | |||||
- grant_option: {{ user['grant_option'] | default(False) }} | - grant_option: {{ user['grant_option'] | default(False) }} | ||||
- user: {{ user.name }} | - user: {{ user.name }} | ||||
- host: '{{ host }}' | - host: '{{ host }}' | ||||
- connection_charset: utf8 | |||||
- connection_user: {{ connection.user }} | |||||
- connection_pass: {{ connection.password }} | |||||
- connection_charset: {{ connection.charset }} | |||||
- require: | - require: | ||||
- mysql_user_{{ user.name }}_{{ host }} | - mysql_user_{{ user.name }}_{{ host }} | ||||
{%- endif %} | {%- endif %} | ||||
{%- if 'databases' in user %} | {%- if 'databases' in user %} | ||||
{% for db in user['databases'] %} | |||||
mysql_user_{{ user.name }}_{{ host }}_grants_db_{{ db }} ~ '_' ~ loop.index0: | |||||
{%- for db in user['databases'] %} | |||||
mysql_user_{{ user.name }}_{{ host }}_grants_db_{{ db.database }}_{{ loop.index0 }}: | |||||
mysql_grants.present: | mysql_grants.present: | ||||
- name: {{ user.name ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }} | - name: {{ user.name ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }} | ||||
- grant: {{db['grants']|sequence|join(",")}} | - grant: {{db['grants']|sequence|join(",")}} | ||||
- grant_option: {{ db['grant_option'] | default(False) }} | - grant_option: {{ db['grant_option'] | default(False) }} | ||||
- user: {{ user.name }} | - user: {{ user.name }} | ||||
- host: '{{ host }}' | - host: '{{ host }}' | ||||
- connection_charset: utf8 | |||||
- connection_user: {{ connection.user }} | |||||
- connection_pass: {{ connection.password }} | |||||
- connection_charset: {{ connection.charset }} | |||||
- require: | - require: | ||||
- mysql_user_{{ user.name }}_{{ host }} | - mysql_user_{{ user.name }}_{{ host }} | ||||
- mysql_database_{{ db }} | |||||
- mysql_database_{{ db.database }} | |||||
{%- endfor %} | {%- endfor %} | ||||
{%- endif %} | {%- endif %} | ||||
{%- endfor %} | |||||
{%- endfor %} | |||||
{%- endif %} | {%- endif %} | ||||
{%- set _galera_xinetd_srv = [] %} | |||||
{%- for server_name, server in slave.get('bind', {}).iteritems() %} | |||||
{%- if server.get.get('clustercheck', {}).get('enabled', False) == True %} | |||||
{%- for bind in slave.bind %} | |||||
{%- set index = '_{0}_{1}'.format(bind.address, bind.port) %} | |||||
{%- set _ccheck = server.clustercheck %} | |||||
{%- do _galera_xinetd_srv.append('clustercheck') %} | |||||
/etc/xinetd.d/mysql_clustercheck{{ index }}_{{ _ccheck.get('clustercheckport', 9200) }}: | |||||
file.managed: | |||||
- source: salt://galera/files/xinet.d.conf | |||||
- template: jinja | |||||
- defaults: | |||||
user: nobody | |||||
# FIXME, add optins if check_attr host/port is defined etc.. | |||||
server: '/usr/local/bin/clustercheck {{ _ccheck.get('user', 'clustercheck') }} {{ _ccheck.get('password', 'clustercheck') }} {{ _ccheck.get('available_when_donor', 0) }} {{ _ccheck.get('available_when_readonly', 0) }}' | |||||
port: _ccheck.get('port', 9200) | |||||
flags: REUSE | |||||
per_source: UNLIMITED | |||||
- require: | |||||
- file: /usr/local/bin/mysql_clustercheck | |||||
- watch_in: | |||||
- galera_xinetd_service | |||||
{%- endfor %} | {%- endfor %} | ||||
{%- endif %} | |||||
{%- endfor %} | {%- endfor %} | ||||
{% if 'clustercheck' in _galera_xinetd_srv %} | |||||
clustercheck_dir: | |||||
file.directory: | |||||
- name: /usr/local/bin/ | |||||
- user: root | |||||
- group: root | |||||
- mode: 750 | |||||
/usr/local/bin/mysql_clustercheck: | |||||
file.managed: | |||||
- source: salt://galera/files/clustercheck.sh | |||||
- user: root | |||||
- group: root | |||||
- mode: 755 | |||||
- require: | |||||
- file: clustercheck_dir | |||||
{%- endif %} | {%- endif %} | ||||
{%- if _galera_xinetd_srv|length > 0 %} | |||||
haproxy_xinetd_package: | |||||
pkg.installed: | |||||
- name: xinetd | |||||
galera_xinetd_service: | |||||
service.running: | |||||
- name: xinetd | |||||
- require: | |||||
- pkg: xinetd | |||||
{%- endif %} | |||||
{%- if _galera_xinetd_srv|length > 0 %} | |||||
haproxy_xinetd_package: | |||||
pkg.installed: | |||||
- name: xinetd | |||||
galera_xinetd_service: | |||||
service.running: | |||||
- name: xinetd | |||||
- require: | |||||
- pkg: xinetd | |||||
{%- endif %} | |||||
{%- endif %} |
- require: | - require: | ||||
- file: galera_run_dir | - file: galera_run_dir | ||||
- file: galera_init_script | - file: galera_init_script | ||||
- timeout: 1800 | |||||
galera_bootstrap_set_root_password: | galera_bootstrap_set_root_password: | ||||
cmd.run: | cmd.run: | ||||
- require: | - require: | ||||
- file: galera_bootstrap_init_config | - file: galera_bootstrap_init_config | ||||
- file: galera_bootstrap_script | - file: galera_bootstrap_script | ||||
- timeout: 1800 | |||||
galera_bootstrap_finish_flag: | galera_bootstrap_finish_flag: | ||||
file.touch: | file.touch: | ||||
{%- endif %} | {%- endif %} | ||||
{%- if not grains.get('noservices', False) %} | {%- if not grains.get('noservices', False) %} | ||||
galera_service: | galera_service: | ||||
service.running: | service.running: | ||||
- name: {{ slave.service }} | - name: {{ slave.service }} | ||||
- enable: true | - enable: true | ||||
- reload: true | - reload: true | ||||
{%- endif %} | |||||
{%- set _galera_xinetd_srv = [] %} | |||||
{%- for server_name, server in master.get('bind', {}).iteritems() %} | |||||
{%- if server.get.get('clustercheck', {}).get('enabled', False) == True %} | |||||
{%- for bind in slave.bind %} | |||||
{%- set index = '_{0}_{1}'.format(bind.address, bind.port) %} | |||||
{%- set _ccheck = server.clustercheck %} | |||||
{%- do _galera_xinetd_srv.append('clustercheck') %} | |||||
/etc/xinetd.d/mysql_clustercheck{{ index }}_{{ _ccheck.get('clustercheckport', 9200) }}: | |||||
file.managed: | |||||
- source: salt://galera/files/xinet.d.conf | |||||
- template: jinja | |||||
- defaults: | |||||
user: nobody | |||||
# FIXME, add optins if check_attr host/port is defined etc.. | |||||
server: '/usr/local/bin/clustercheck {{ _ccheck.get('user', 'clustercheck') }} {{ _ccheck.get('password', 'clustercheck') }} {{ _ccheck.get('available_when_donor', 0) }} {{ _ccheck.get('available_when_readonly', 0) }}' | |||||
port: _ccheck.get('port', 9200) | |||||
flags: REUSE | |||||
per_source: UNLIMITED | |||||
- require: | |||||
- file: /usr/local/bin/mysql_clustercheck | |||||
- watch_in: | |||||
- galera_xinetd_service | |||||
{%- endfor %} | |||||
{%- endif %} | |||||
{%- endfor %} | |||||
{% if 'clustercheck' in _galera_xinetd_srv %} | |||||
clustercheck_dir: | |||||
file.directory: | |||||
- name: /usr/local/bin/ | |||||
- user: root | |||||
- group: root | |||||
- mode: 750 | |||||
/usr/local/bin/mysql_clustercheck: | |||||
file.managed: | |||||
- source: salt://galera/files/clustercheck.sh | |||||
- user: root | |||||
- group: root | |||||
- mode: 755 | |||||
- require: | |||||
- file: clustercheck_dir | |||||
{%- endif %} | |||||
{%- if _galera_xinetd_srv|length > 0 %} | |||||
haproxy_xinetd_package: | |||||
pkg.installed: | |||||
- name: xinetd | |||||
galera_xinetd_service: | |||||
service.running: | |||||
- name: xinetd | |||||
- require: | |||||
- pkg: xinetd | |||||
{%- endif %} | {%- endif %} | ||||
port: 3306 | port: 3306 | ||||
maintenance_password: password | maintenance_password: password | ||||
admin: | admin: | ||||
user: user | |||||
user: root | |||||
password: password | password: password | ||||
members: | members: | ||||
- host: 127.0.0.1 | - host: 127.0.0.1 | ||||
port: 4567 | port: 4567 | ||||
- host: 127.0.0.1 | - host: 127.0.0.1 | ||||
port: 4567 | port: 4567 | ||||
clustercheck: | |||||
enabled: True | |||||
user: clustercheck | |||||
password: password | |||||
available_when_donor: 1 | |||||
available_when_readonly: 1 | |||||
port: 9200 | |||||
mysql: | mysql: | ||||
server: | server: | ||||
users: | users: | ||||
host: 127.0.0.1 | host: 127.0.0.1 | ||||
- name: clustercheck | - name: clustercheck | ||||
#host: localhost | #host: localhost | ||||
password: clustercheck | |||||
password: password | |||||
database: '*.*' | database: '*.*' | ||||
grants: PROCESS | grants: PROCESS | ||||
grant_option: False | |||||
- name: inspector | - name: inspector | ||||
host: 127.0.0.1 | host: 127.0.0.1 | ||||
password: password | password: password | ||||
databases: | databases: | ||||
mydb: | |||||
- database: mydb | |||||
- table: mytable | |||||
- grant_option: False | |||||
- grants: | |||||
- all privileges | |||||
- database: mydb | |||||
table: mytable | |||||
grant_option: True | |||||
grants: | |||||
- all privileges |
port: 3306 | port: 3306 | ||||
maintenance_password: password | maintenance_password: password | ||||
admin: | admin: | ||||
user: user | |||||
user: root | |||||
password: password | password: password | ||||
members: | members: | ||||
- host: 127.0.0.1 | - host: 127.0.0.1 | ||||
port: 4567 | port: 4567 | ||||
- host: 127.0.0.1 | - host: 127.0.0.1 | ||||
port: 4567 | port: 4567 | ||||
clustercheck: | |||||
enabled: True | |||||
user: clustercheck | |||||
password: password | |||||
available_when_donor: 1 | |||||
available_when_readonly: 1 | |||||
port: 9200 | |||||
mysql: | mysql: | ||||
server: | server: | ||||
users: | users: | ||||
- name: haproxy | - name: haproxy | ||||
host: '%' | host: '%' | ||||
- name: haproxy | - name: haproxy | ||||
host: 127.0.0.1 | |||||
host: 127.0.0.1 | |||||
- name: clustercheck | |||||
#host: localhost | |||||
password: password | |||||
database: '*.*' | |||||
grants: PROCESS |
run() { | run() { | ||||
for pillar in ${PILLARDIR}/*.sls; do | for pillar in ${PILLARDIR}/*.sls; do | ||||
state_name=$(basename ${pillar%.sls}) | state_name=$(basename ${pillar%.sls}) | ||||
salt_run grains.set 'noservices' False force=True | |||||
salt_run --id=${state_name} state.show_sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1) | salt_run --id=${state_name} state.show_sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1) | ||||
done | done | ||||
} | } |