Saltstack Official Galera Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
5.0KB

  1. {%- if pillar.get('mysql', {}).server is defined %}
  2. {%- set server = pillar.mysql.server %}
  3. {%- for database_name, database in server.get('database', {}).iteritems() %}
  4. mysql_database_{{ database_name }}:
  5. mysql_database.present:
  6. - name: {{ database_name }}
  7. {%- for user in database.users %}
  8. mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}:
  9. mysql_user.present:
  10. - host: '{{ user.host }}'
  11. - name: '{{ user.name }}'
  12. - password: {{ user.password }}
  13. mysql_grants_{{ user.name }}_{{ database_name }}_{{ user.host }}:
  14. mysql_grants.present:
  15. - grant: {{ user.rights }}
  16. - database: '{{ database_name }}.*'
  17. - user: '{{ user.name }}'
  18. - host: '{{ user.host }}'
  19. - require:
  20. - mysql_user: mysql_user_{{ user.name }}_{{ database_name }}_{{ user.host }}
  21. - mysql_database: mysql_database_{{ database_name }}
  22. {%- endfor %}
  23. {%- if database.initial_data is defined %}
  24. /root/mysql/scripts/restore_{{ database_name }}.sh:
  25. file.managed:
  26. - source: salt://mysql/conf/restore.sh
  27. - mode: 770
  28. - template: jinja
  29. - defaults:
  30. database_name: {{ database_name }}
  31. database: {{ database }}
  32. - require:
  33. - file: mysql_dirs
  34. - mysql_database: mysql_database_{{ database_name }}
  35. restore_mysql_database_{{ database_name }}:
  36. cmd.run:
  37. - name: /root/mysql/scripts/restore_{{ database_name }}.sh
  38. - unless: "[ -f /root/mysql/flags/{{ database_name }}-installed ]"
  39. - cwd: /root
  40. - require:
  41. - file: /root/mysql/scripts/restore_{{ database_name }}.sh
  42. {%- endif %}
  43. {%- endfor %}
  44. {%- if not grains.get('noservices', False) %}
  45. {%- for user in server.get('users', []) %}
  46. {%- set user_hosts = user.get('hosts', user.get('host', 'localhost'))|sequence %}
  47. {%- for host in user_hosts %}
  48. mysql_user_{{ user.name }}_{{ host }}:
  49. mysql_user.present:
  50. - host: '{{ user.host }}'
  51. - name: '{{ user.name }}'
  52. {%- if user['password_hash'] is defined %}
  53. - password_hash: '{{ user.password_hash }}'
  54. {%- elif user['password'] is defined and user['password'] != None %}
  55. - password: '{{ user.password }}'
  56. {%- else %}
  57. - allow_passwordless: True
  58. {%- endif %}
  59. - connection_charset: utf8
  60. {%- if 'grants' in user %}
  61. mysql_user_{{ user.name }}_{{ host }}_grants:
  62. mysql_grants.present:
  63. - name: {{ user.name }}
  64. - grant: {{ user['grants']|sequence|join(",") }}
  65. - database: '*.*'
  66. - grant_option: {{ user['grant_option'] | default(False) }}
  67. - user: {{ user.name }}
  68. - host: '{{ host }}'
  69. - connection_charset: utf8
  70. - require:
  71. - mysql_user_{{ user.name }}_{{ host }}
  72. {%- endif %}
  73. {%- if 'databases' in user %}
  74. {% for db in user['databases'] %}
  75. mysql_user_{{ user.name }}_{{ host }}_grants_db_{{ db }} ~ '_' ~ loop.index0:
  76. mysql_grants.present:
  77. - name: {{ user.name ~ '_' ~ db['database'] ~ '_' ~ db['table'] | default('all') }}
  78. - grant: {{db['grants']|sequence|join(",")}}
  79. - database: '{{ db['database'] }}.{{ db['table'] | default('*') }}'
  80. - grant_option: {{ db['grant_option'] | default(False) }}
  81. - user: {{ user.name }}
  82. - host: '{{ host }}'
  83. - connection_charset: utf8
  84. - require:
  85. - mysql_user_{{ user.name }}_{{ host }}
  86. - mysql_database_{{ db }}
  87. {%- endfor %}
  88. {%- endif %}
  89. {%- endfor %}
  90. {%- endfor %}
  91. {%- endif %}
  92. {%- set _galera_xinetd_srv = [] %}
  93. {%- for server_name, server in slave.get('bind', {}).iteritems() %}
  94. {%- if server.get.get('clustercheck', {}).get('enabled', False) == True %}
  95. {%- for bind in slave.bind %}
  96. {%- set index = '_{0}_{1}'.format(bind.address, bind.port) %}
  97. {%- set _ccheck = server.clustercheck %}
  98. {%- do _galera_xinetd_srv.append('clustercheck') %}
  99. /etc/xinetd.d/mysql_clustercheck{{ index }}_{{ _ccheck.get('clustercheckport', 9200) }}:
  100. file.managed:
  101. - source: salt://galera/files/xinet.d.conf
  102. - template: jinja
  103. - defaults:
  104. user: nobody
  105. # FIXME, add optins if check_attr host/port is defined etc..
  106. 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) }}'
  107. port: _ccheck.get('port', 9200)
  108. flags: REUSE
  109. per_source: UNLIMITED
  110. - require:
  111. - file: /usr/local/bin/mysql_clustercheck
  112. - watch_in:
  113. - galera_xinetd_service
  114. {%- endfor %}
  115. {%- endif %}
  116. {%- endfor %}
  117. {% if 'clustercheck' in _galera_xinetd_srv %}
  118. clustercheck_dir:
  119. file.directory:
  120. - name: /usr/local/bin/
  121. - user: root
  122. - group: root
  123. - mode: 750
  124. /usr/local/bin/mysql_clustercheck:
  125. file.managed:
  126. - source: salt://galera/files/clustercheck.sh
  127. - user: root
  128. - group: root
  129. - mode: 755
  130. - require:
  131. - file: clustercheck_dir
  132. {%- endif %}
  133. {%- if _galera_xinetd_srv|length > 0 %}
  134. haproxy_xinetd_package:
  135. pkg.installed:
  136. - name: xinetd
  137. galera_xinetd_service:
  138. service.running:
  139. - name: xinetd
  140. - require:
  141. - pkg: xinetd
  142. {%- endif %}
  143. {%- endif %}
  144. {%- if _galera_xinetd_srv|length > 0 %}
  145. haproxy_xinetd_package:
  146. pkg.installed:
  147. - name: xinetd
  148. galera_xinetd_service:
  149. service.running:
  150. - name: xinetd
  151. - require:
  152. - pkg: xinetd
  153. {%- endif %}
  154. {%- endif %}