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

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