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.

229 lines
5.2KB

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