Saltstack Official Galera Formula
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

238 lines
5.4KB

  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_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: {{ slave|yaml }}
  105. - template: jinja
  106. galera_bootstrap_script:
  107. file.managed:
  108. - name: /usr/local/sbin/galera_bootstrap.sh
  109. - mode: 750
  110. - defaults:
  111. service: {{ slave|yaml }}
  112. slave: True
  113. - source: salt://galera/files/bootstrap.sh
  114. - template: jinja
  115. {%- if salt['cmd.shell']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
  116. {%- if salt['cmd.shell']('test -e /etc/salt/.galera_bootstrap; echo $?') != '0' %}
  117. # Enforce config before package installation
  118. galera_pre_config:
  119. file.managed:
  120. - name: {{ slave.config }}
  121. - source: salt://galera/files/my.cnf.pre
  122. - mode: 644
  123. - template: jinja
  124. - makedirs: true
  125. - require_in:
  126. - pkg: galera_packages
  127. galera_init_start_service:
  128. cmd.run:
  129. - name: /usr/local/sbin/galera_init.sh
  130. {%- if grains.get('noservices') %}
  131. - onlyif: /bin/false
  132. {%- endif %}
  133. - require:
  134. - file: galera_run_dir
  135. - file: galera_init_script
  136. - timeout: 1800
  137. galera_bootstrap_set_root_password:
  138. cmd.run:
  139. - name: mysqladmin password "{{ slave.admin.password }}"
  140. {%- if grains.get('noservices') %}
  141. - onlyif: /bin/false
  142. {%- endif %}
  143. - require:
  144. - cmd: galera_init_start_service
  145. mysql_bootstrap_update_maint_password:
  146. cmd.run:
  147. - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
  148. {%- if grains.get('noservices') %}
  149. - onlyif: /bin/false
  150. {%- endif %}
  151. - require:
  152. - cmd: galera_bootstrap_set_root_password
  153. galera_bootstrap_stop_service:
  154. service.dead:
  155. - name: {{ slave.service }}
  156. {%- if not grains.get('noservices', False) %}
  157. - require:
  158. - cmd: mysql_bootstrap_update_maint_password
  159. {%- else %}
  160. - onlyif: /bin/false
  161. {%- endif %}
  162. galera_bootstrap_init_config:
  163. file.managed:
  164. - name: {{ slave.config }}
  165. - source: salt://galera/files/my.cnf
  166. - mode: 644
  167. - template: jinja
  168. - require:
  169. - service: galera_bootstrap_stop_service
  170. galera_bootstrap_start_service_final:
  171. cmd.run:
  172. - name: /usr/local/sbin/galera_bootstrap.sh
  173. {%- if grains.get('noservices') %}
  174. - onlyif: /bin/false
  175. {%- endif %}
  176. - require:
  177. - file: galera_bootstrap_init_config
  178. - file: galera_bootstrap_script
  179. - timeout: 1800
  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: {{ slave.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: {{ slave.service }}
  199. - enable: true
  200. - reload: true
  201. {%- if grains.get('noservices') %}
  202. - onlyif: /bin/false
  203. {%- endif %}
  204. {%- endif %}
  205. {%- endif %}