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.

238 line
5.4KB

  1. {%- from "galera/map.jinja" import master with context %}
  2. {%- if master.get('enabled', False) %}
  3. {%- if master.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: {{ master.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: {{ master.pkgs }}
  28. - refresh: true
  29. - force_yes: True
  30. galera_dirs:
  31. file.directory:
  32. - names: ['/var/log/mysql', '/etc/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: 750
  102. - source: salt://galera/files/init_bootstrap.sh
  103. - defaults:
  104. service: {{ master|yaml }}
  105. - template: jinja
  106. - timeout: 1800
  107. galera_bootstrap_script:
  108. file.managed:
  109. - name: /usr/local/sbin/galera_bootstrap.sh
  110. - mode: 750
  111. - source: salt://galera/files/bootstrap.sh
  112. - defaults:
  113. service: {{ master|yaml }}
  114. slave: False
  115. - template: jinja
  116. {%- if salt['cmd.shell']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
  117. {%- if salt['cmd.shell']('test -e /etc/salt/.galera_bootstrap; echo $?') != '0' %}
  118. # Enforce config before package installation
  119. galera_pre_config:
  120. file.managed:
  121. - name: {{ master.config }}
  122. - source: salt://galera/files/my.cnf.pre
  123. - mode: 644
  124. - template: jinja
  125. - makedirs: True
  126. - require_in:
  127. - pkg: galera_packages
  128. galera_init_start_service:
  129. cmd.run:
  130. - name: /usr/local/sbin/galera_init.sh
  131. {%- if grains.get('noservices') %}
  132. - onlyif: /bin/false
  133. {%- endif %}
  134. - require:
  135. - file: galera_run_dir
  136. - file: galera_init_script
  137. - timeout: 1800
  138. galera_bootstrap_set_root_password:
  139. cmd.run:
  140. - name: mysqladmin password "{{ master.admin.password }}"
  141. {%- if grains.get('noservices') %}
  142. - onlyif: /bin/false
  143. {%- endif %}
  144. - require:
  145. - cmd: galera_init_start_service
  146. mysql_bootstrap_update_maint_password:
  147. cmd.run:
  148. - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
  149. {%- if grains.get('noservices') %}
  150. - onlyif: /bin/false
  151. {%- endif %}
  152. - require:
  153. - cmd: galera_bootstrap_set_root_password
  154. galera_bootstrap_stop_service:
  155. service.dead:
  156. - name: {{ master.service }}
  157. {%- if not grains.get('noservices', False) %}
  158. - require:
  159. - cmd: mysql_bootstrap_update_maint_password
  160. {%- else %}
  161. - onlyif: /bin/false
  162. {%- endif %}
  163. galera_bootstrap_init_config:
  164. file.managed:
  165. - name: {{ master.config }}
  166. - source: salt://galera/files/my.cnf.init
  167. - mode: 644
  168. - template: jinja
  169. - require:
  170. - service: galera_bootstrap_stop_service
  171. galera_bootstrap_start_service_final:
  172. cmd.run:
  173. - name: /usr/local/sbin/galera_bootstrap.sh
  174. {%- if grains.get('noservices') %}
  175. - onlyif: /bin/false
  176. {%- endif %}
  177. - require:
  178. - file: galera_bootstrap_init_config
  179. - file: galera_bootstrap_script
  180. galera_bootstrap_finish_flag:
  181. file.touch:
  182. - name: /etc/salt/.galera_bootstrap
  183. - require:
  184. - cmd: galera_bootstrap_start_service_final
  185. - watch_in:
  186. - file: galera_config
  187. {%- endif %}
  188. galera_config:
  189. file.managed:
  190. - name: {{ master.config }}
  191. - source: salt://galera/files/my.cnf
  192. - mode: 644
  193. - template: jinja
  194. - require_in:
  195. - service: galera_service
  196. galera_service:
  197. service.running:
  198. - name: {{ master.service }}
  199. - enable: true
  200. - reload: true
  201. {%- if grains.get('noservices') %}
  202. - onlyif: /bin/false
  203. {%- endif %}
  204. {%- endif %}
  205. {%- endif %}