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.

235 lines
5.3KB

  1. {%- from "galera/map.jinja" import slave with context %}
  2. {%- if slave.get('enabled', False) %}
  3. {%- if slave.get('ssl', {}).get('enabled', False) %}
  4. include:
  5. - galera._ssl
  6. {%- endif %}
  7. {%- if grains.os_family == 'RedHat' %}
  8. xtrabackup_repo:
  9. pkg.installed:
  10. - sources:
  11. - percona-release: {{ slave.xtrabackup_repo }}
  12. - require_in:
  13. - pkg: galera_packages
  14. # Workaround https://bugs.launchpad.net/percona-server/+bug/1490144
  15. xtrabackup_repo_fix:
  16. cmd.run:
  17. - name: |
  18. sed -i 's,enabled\ =\ 1,enabled\ =\ 1\nexclude\ =\ Percona-XtraDB-\*\ Percona-Server-\*,g' /etc/yum.repos.d/percona-release.repo
  19. - unless: 'grep "exclude = Percona-XtraDB-\*" /etc/yum.repos.d/percona-release.repo'
  20. - watch:
  21. - pkg: xtrabackup_repo
  22. - require_in:
  23. - pkg: galera_packages
  24. {%- endif %}
  25. galera_packages:
  26. pkg.installed:
  27. - names: {{ slave.pkgs }}
  28. - refresh: true
  29. - force_yes: True
  30. galera_log_dir:
  31. file.directory:
  32. - name: /var/log/mysql
  33. - makedirs: true
  34. - mode: 755
  35. - require:
  36. - pkg: galera_packages
  37. {%- if grains.os_family == 'Debian' %}
  38. galera_run_dir:
  39. file.directory:
  40. - name: /var/run/mysqld
  41. - makedirs: true
  42. - mode: 755
  43. - user: mysql
  44. - group: root
  45. - require:
  46. - pkg: galera_packages
  47. {%- if grains.get('init', None) == "upstart" %}
  48. galera_purge_init:
  49. file.absent:
  50. - name: /etc/init.d/mysql
  51. - require:
  52. - pkg: galera_packages
  53. galera_overide:
  54. file.managed:
  55. - name: /etc/init/mysql.override
  56. - contents: |
  57. limit nofile 102400 102400
  58. exec /usr/bin/mysqld_safe
  59. - require:
  60. - pkg: galera_packages
  61. {%- elif grains.get('init', None) == "systemd" %}
  62. galera_systemd_directory_present:
  63. file.directory:
  64. - name: /etc/systemd/system/mysql.service.d
  65. - user: root
  66. - group: root
  67. - mode: 755
  68. - require:
  69. - pkg: galera_packages
  70. galera_override_limit_no_file:
  71. file.managed:
  72. - name: /etc/systemd/system/mysql.service.d/override.conf
  73. - contents: |
  74. [Service]
  75. LimitNOFILE=1024000
  76. - require:
  77. - pkg: galera_packages
  78. - file: galera_systemd_directory_present
  79. - watch_in:
  80. - service: galera_service
  81. mysql_restart_systemd:
  82. module.wait:
  83. - name: service.systemctl_reload
  84. - watch:
  85. - file: /etc/systemd/system/mysql.service.d/override.conf
  86. - require_in:
  87. - service: galera_service
  88. {%- endif %}
  89. galera_conf_debian:
  90. file.managed:
  91. - name: /etc/mysql/debian.cnf
  92. - template: jinja
  93. - source: salt://galera/files/debian.cnf
  94. - mode: 640
  95. - require:
  96. - pkg: galera_packages
  97. {%- endif %}
  98. galera_init_script:
  99. file.managed:
  100. - name: /usr/local/sbin/galera_init.sh
  101. - mode: 755
  102. - source: salt://galera/files/init_bootstrap.sh
  103. - defaults:
  104. service: {{ slave|yaml }}
  105. - template: jinja
  106. galera_bootstrap_script:
  107. file.managed:
  108. - name: /usr/local/sbin/galera_bootstrap.sh
  109. - mode: 755
  110. - defaults:
  111. service: {{ slave|yaml }}
  112. - source: salt://galera/files/bootstrap.sh
  113. - template: jinja
  114. {%- if salt['cmd.run']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
  115. # Enforce config before package installation
  116. galera_pre_config:
  117. file.managed:
  118. - name: {{ slave.config }}
  119. - source: salt://galera/files/my.cnf.pre
  120. - mode: 644
  121. - template: jinja
  122. - makedirs: true
  123. - require_in:
  124. - pkg: galera_packages
  125. galera_init_start_service:
  126. cmd.run:
  127. - name: /usr/local/sbin/galera_init.sh
  128. {%- if grains.get('noservices') %}
  129. - onlyif: /bin/false
  130. {%- endif %}
  131. - require:
  132. - file: galera_run_dir
  133. - file: galera_init_script
  134. - timeout: 1800
  135. galera_bootstrap_set_root_password:
  136. cmd.run:
  137. - name: mysqladmin password "{{ slave.admin.password }}"
  138. {%- if grains.get('noservices') %}
  139. - onlyif: /bin/false
  140. {%- endif %}
  141. - require:
  142. - cmd: galera_init_start_service
  143. mysql_bootstrap_update_maint_password:
  144. cmd.run:
  145. - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
  146. {%- if grains.get('noservices') %}
  147. - onlyif: /bin/false
  148. {%- endif %}
  149. - require:
  150. - cmd: galera_bootstrap_set_root_password
  151. galera_bootstrap_stop_service:
  152. service.dead:
  153. - name: {{ slave.service }}
  154. {%- if not grains.get('noservices', False) %}
  155. - require:
  156. - cmd: mysql_bootstrap_update_maint_password
  157. {%- else %}
  158. - onlyif: /bin/false
  159. {%- endif %}
  160. galera_bootstrap_init_config:
  161. file.managed:
  162. - name: {{ slave.config }}
  163. - source: salt://galera/files/my.cnf
  164. - mode: 644
  165. - template: jinja
  166. - require:
  167. - service: galera_bootstrap_stop_service
  168. galera_bootstrap_start_service_final:
  169. cmd.run:
  170. - name: /usr/local/sbin/galera_bootstrap.sh
  171. {%- if grains.get('noservices') %}
  172. - onlyif: /bin/false
  173. {%- endif %}
  174. - require:
  175. - file: galera_bootstrap_init_config
  176. - file: galera_bootstrap_script
  177. - timeout: 1800
  178. galera_bootstrap_finish_flag:
  179. file.touch:
  180. - name: /var/lib/mysql/.galera_bootstrap
  181. - require:
  182. - cmd: galera_bootstrap_start_service_final
  183. - watch_in:
  184. - file: galera_config
  185. {%- endif %}
  186. galera_config:
  187. file.managed:
  188. - name: {{ slave.config }}
  189. - source: salt://galera/files/my.cnf
  190. - mode: 644
  191. - template: jinja
  192. - require_in:
  193. - service: galera_service
  194. galera_service:
  195. service.running:
  196. - name: {{ slave.service }}
  197. - enable: true
  198. - reload: true
  199. {%- if grains.get('noservices') %}
  200. - onlyif: /bin/false
  201. {%- endif %}
  202. {%- endif %}