Saltstack Official Galera Formula
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

198 lines
4.5KB

  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. {%- endif %}
  58. galera_conf_debian:
  59. file.managed:
  60. - name: /etc/mysql/debian.cnf
  61. - template: jinja
  62. - source: salt://galera/files/debian.cnf
  63. - mode: 640
  64. - require:
  65. - pkg: galera_packages
  66. {%- endif %}
  67. galera_init_script:
  68. file.managed:
  69. - name: /usr/local/sbin/galera_init.sh
  70. - mode: 755
  71. - source: salt://galera/files/init_bootstrap.sh
  72. - defaults:
  73. service: {{ master|yaml }}
  74. - template: jinja
  75. - timeout: 1800
  76. galera_bootstrap_script:
  77. file.managed:
  78. - name: /usr/local/sbin/galera_bootstrap.sh
  79. - mode: 755
  80. - source: salt://galera/files/bootstrap.sh
  81. - defaults:
  82. service: {{ master|yaml }}
  83. - template: jinja
  84. {%- if salt['cmd.run']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
  85. # Enforce config before package installation
  86. galera_pre_config:
  87. file.managed:
  88. - name: {{ master.config }}
  89. - source: salt://galera/files/my.cnf.pre
  90. - mode: 644
  91. - template: jinja
  92. - makedirs: True
  93. - require_in:
  94. - pkg: galera_packages
  95. {%- if not grains.get('noservices', False) %}
  96. galera_init_start_service:
  97. cmd.run:
  98. - name: /usr/local/sbin/galera_init.sh
  99. - require:
  100. - file: galera_run_dir
  101. - file: galera_init_script
  102. - timeout: 1800
  103. galera_bootstrap_set_root_password:
  104. cmd.run:
  105. - name: mysqladmin password "{{ master.admin.password }}"
  106. - require:
  107. - cmd: galera_init_start_service
  108. mysql_bootstrap_update_maint_password:
  109. cmd.run:
  110. - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
  111. - require:
  112. - cmd: galera_bootstrap_set_root_password
  113. galera_bootstrap_stop_service:
  114. service.dead:
  115. - name: {{ master.service }}
  116. {%- if not grains.get('noservices', False) %}
  117. - require:
  118. - cmd: mysql_bootstrap_update_maint_password
  119. {%- endif %}
  120. {%- endif %}
  121. galera_bootstrap_init_config:
  122. file.managed:
  123. - name: {{ master.config }}
  124. - source: salt://galera/files/my.cnf.init
  125. - mode: 644
  126. - template: jinja
  127. {%- if not grains.get('noservices', False) %}
  128. - require:
  129. - service: galera_bootstrap_stop_service
  130. {%- endif %}
  131. {%- if not grains.get('noservices', False) %}
  132. galera_bootstrap_start_service_final:
  133. cmd.run:
  134. - name: /usr/local/sbin/galera_bootstrap.sh
  135. - require:
  136. - file: galera_bootstrap_init_config
  137. - file: galera_bootstrap_script
  138. {%- endif %}
  139. galera_bootstrap_finish_flag:
  140. file.touch:
  141. - name: /var/lib/mysql/.galera_bootstrap
  142. {%- if not grains.get('noservices', False) %}
  143. - require:
  144. - cmd: galera_bootstrap_start_service_final
  145. {%- endif %}
  146. - watch_in:
  147. - file: galera_config
  148. {%- endif %}
  149. galera_config:
  150. file.managed:
  151. - name: {{ master.config }}
  152. - source: salt://galera/files/my.cnf
  153. - mode: 644
  154. - template: jinja
  155. {%- if not grains.get('noservices', False) %}
  156. - require_in:
  157. - service: galera_service
  158. {%- endif %}
  159. {%- if not grains.get('noservices', False) %}
  160. galera_service:
  161. service.running:
  162. - name: {{ master.service }}
  163. - enable: true
  164. - reload: true
  165. {%- endif %}
  166. {%- endif %}