Saltstack Official Galera Formula
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

176 rindas
4.0KB

  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. galera_log_dir:
  26. file.directory:
  27. - name: /var/log/mysql
  28. - makedirs: true
  29. - mode: 755
  30. - require:
  31. - pkg: galera_packages
  32. {%- if grains.os_family == 'Debian' %}
  33. galera_run_dir:
  34. file.directory:
  35. - name: /var/run/mysqld
  36. - makedirs: true
  37. - mode: 755
  38. - user: mysql
  39. - group: root
  40. - require:
  41. - pkg: galera_packages
  42. {%- if grains.get('init', None) == "upstart" %}
  43. galera_purge_init:
  44. file.absent:
  45. - name: /etc/init.d/mysql
  46. - require:
  47. - pkg: galera_packages
  48. galera_overide:
  49. file.managed:
  50. - name: /etc/init/mysql.override
  51. - contents: |
  52. limit nofile 102400 102400
  53. exec /usr/bin/mysqld_safe
  54. - require:
  55. - pkg: galera_packages
  56. {%- endif %}
  57. galera_conf_debian:
  58. file.managed:
  59. - name: /etc/mysql/debian.cnf
  60. - template: jinja
  61. - source: salt://galera/files/debian.cnf
  62. - mode: 640
  63. - require:
  64. - pkg: galera_packages
  65. {%- endif %}
  66. galera_init_script:
  67. file.managed:
  68. - name: /usr/local/sbin/galera_init.sh
  69. - mode: 755
  70. - source: salt://galera/files/init_bootstrap.sh
  71. - defaults:
  72. service: {{ master|yaml }}
  73. - template: jinja
  74. galera_bootstrap_script:
  75. file.managed:
  76. - name: /usr/local/sbin/galera_bootstrap.sh
  77. - mode: 755
  78. - source: salt://galera/files/bootstrap.sh
  79. - defaults:
  80. service: {{ master|yaml }}
  81. - template: jinja
  82. {%- if salt['cmd.run']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
  83. # Enforce config before package installation
  84. galera_pre_config:
  85. file.managed:
  86. - name: {{ master.config }}
  87. - source: salt://galera/files/my.cnf.pre
  88. - mode: 644
  89. - template: jinja
  90. - makedirs: True
  91. - require_in:
  92. - pkg: galera_packages
  93. galera_init_start_service:
  94. cmd.run:
  95. - name: /usr/local/sbin/galera_init.sh
  96. - require:
  97. - file: galera_run_dir
  98. - file: galera_init_script
  99. galera_bootstrap_set_root_password:
  100. cmd.run:
  101. - name: mysqladmin password "{{ master.admin.password }}"
  102. - require:
  103. - cmd: galera_init_start_service
  104. mysql_bootstrap_update_maint_password:
  105. cmd.run:
  106. - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
  107. - require:
  108. - cmd: galera_bootstrap_set_root_password
  109. galera_bootstrap_stop_service:
  110. service.dead:
  111. - name: {{ master.service }}
  112. - require:
  113. - cmd: mysql_bootstrap_update_maint_password
  114. galera_bootstrap_init_config:
  115. file.managed:
  116. - name: {{ master.config }}
  117. - source: salt://galera/files/my.cnf.init
  118. - mode: 644
  119. - template: jinja
  120. - require:
  121. - service: galera_bootstrap_stop_service
  122. galera_bootstrap_start_service_final:
  123. cmd.run:
  124. - name: /usr/local/sbin/galera_bootstrap.sh
  125. - require:
  126. - file: galera_bootstrap_init_config
  127. - file: galera_bootstrap_script
  128. galera_bootstrap_finish_flag:
  129. file.touch:
  130. - name: /var/lib/mysql/.galera_bootstrap
  131. - require:
  132. - cmd: galera_bootstrap_start_service_final
  133. - watch_in:
  134. - file: galera_config
  135. {%- endif %}
  136. galera_config:
  137. file.managed:
  138. - name: {{ master.config }}
  139. - source: salt://galera/files/my.cnf
  140. - mode: 644
  141. - template: jinja
  142. - require_in:
  143. - service: galera_service
  144. galera_service:
  145. service.running:
  146. - name: {{ master.service }}
  147. - enable: true
  148. - reload: true
  149. {%- endif %}