Saltstack Official Galera Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.7KB

  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. galera_init_start_service:
  84. cmd.run:
  85. - name: /usr/local/sbin/galera_init.sh
  86. - require:
  87. - file: galera_run_dir
  88. - file: galera_init_script
  89. galera_bootstrap_set_root_password:
  90. cmd.run:
  91. - name: mysqladmin password "{{ master.admin.password }}"
  92. - require:
  93. - cmd: galera_init_start_service
  94. mysql_bootstrap_update_maint_password:
  95. cmd.run:
  96. - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
  97. - require:
  98. - cmd: galera_bootstrap_set_root_password
  99. galera_bootstrap_stop_service:
  100. service.dead:
  101. - name: {{ master.service }}
  102. - require:
  103. - cmd: mysql_bootstrap_update_maint_password
  104. galera_bootstrap_init_config:
  105. file.managed:
  106. - name: {{ master.config }}
  107. - source: salt://galera/files/my.cnf.init
  108. - mode: 644
  109. - template: jinja
  110. - require:
  111. - service: galera_bootstrap_stop_service
  112. galera_bootstrap_start_service_final:
  113. cmd.run:
  114. - name: /usr/local/sbin/galera_bootstrap.sh
  115. - require:
  116. - file: galera_bootstrap_init_config
  117. - file: galera_bootstrap_script
  118. galera_bootstrap_finish_flag:
  119. file.touch:
  120. - name: /var/lib/mysql/.galera_bootstrap
  121. - require:
  122. - cmd: galera_bootstrap_start_service_final
  123. - watch_in:
  124. - file: galera_config
  125. {%- endif %}
  126. galera_config:
  127. file.managed:
  128. - name: {{ master.config }}
  129. - source: salt://galera/files/my.cnf
  130. - mode: 644
  131. - template: jinja
  132. - require_in:
  133. - service: galera_service
  134. galera_service:
  135. service.running:
  136. - name: {{ master.service }}
  137. - enable: true
  138. - reload: true
  139. {%- endif %}