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.

193 lines
4.3KB

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