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ů.

196 lines
4.4KB

  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. galera_bootstrap_script:
  76. file.managed:
  77. - name: /usr/local/sbin/galera_bootstrap.sh
  78. - mode: 755
  79. - source: salt://galera/files/bootstrap.sh
  80. - defaults:
  81. service: {{ master|yaml }}
  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: {{ master.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. galera_bootstrap_set_root_password:
  102. cmd.run:
  103. - name: mysqladmin password "{{ master.admin.password }}"
  104. - require:
  105. - cmd: galera_init_start_service
  106. mysql_bootstrap_update_maint_password:
  107. cmd.run:
  108. - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
  109. - require:
  110. - cmd: galera_bootstrap_set_root_password
  111. galera_bootstrap_stop_service:
  112. service.dead:
  113. - name: {{ master.service }}
  114. {%- if not grains.get('noservices', False) %}
  115. - require:
  116. - cmd: mysql_bootstrap_update_maint_password
  117. {%- endif %}
  118. {%- endif %}
  119. galera_bootstrap_init_config:
  120. file.managed:
  121. - name: {{ master.config }}
  122. - source: salt://galera/files/my.cnf.init
  123. - mode: 644
  124. - template: jinja
  125. {%- if not grains.get('noservices', False) %}
  126. - require:
  127. - service: galera_bootstrap_stop_service
  128. {%- endif %}
  129. {%- if not grains.get('noservices', False) %}
  130. galera_bootstrap_start_service_final:
  131. cmd.run:
  132. - name: /usr/local/sbin/galera_bootstrap.sh
  133. - require:
  134. - file: galera_bootstrap_init_config
  135. - file: galera_bootstrap_script
  136. {%- endif %}
  137. galera_bootstrap_finish_flag:
  138. file.touch:
  139. - name: /var/lib/mysql/.galera_bootstrap
  140. {%- if not grains.get('noservices', False) %}
  141. - require:
  142. - cmd: galera_bootstrap_start_service_final
  143. {%- endif %}
  144. - watch_in:
  145. - file: galera_config
  146. {%- endif %}
  147. galera_config:
  148. file.managed:
  149. - name: {{ master.config }}
  150. - source: salt://galera/files/my.cnf
  151. - mode: 644
  152. - template: jinja
  153. {%- if not grains.get('noservices', False) %}
  154. - require_in:
  155. - service: galera_service
  156. {%- endif %}
  157. {%- if not grains.get('noservices', False) %}
  158. galera_service:
  159. service.running:
  160. - name: {{ master.service }}
  161. - enable: true
  162. - reload: true
  163. {%- endif %}
  164. {%- endif %}