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.

124 lines
2.9KB

  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. galera_log_dir:
  26. file.directory:
  27. - name: /var/log/mysql
  28. - makedirs: true
  29. - mode: 755
  30. - require:
  31. - pkg: galera_packages
  32. galera_init_script:
  33. file.managed:
  34. - name: /etc/init.d/mysql
  35. - source: salt://galera/files/mysql
  36. - mode: 755
  37. - require:
  38. - pkg: galera_packages
  39. {%- if salt['cmd.run']('test -e /root/.galera_bootstrap; echo $?') != '0' %}
  40. galera_bootstrap_temp_config:
  41. file.managed:
  42. - name: {{ slave.config }}
  43. - source: salt://galera/files/my.cnf.bootstrap
  44. - mode: 644
  45. - template: jinja
  46. - require:
  47. - pkg: galera_packages
  48. - file: galera_init_script
  49. galera_bootstrap_start_service:
  50. service.running:
  51. - name: {{ slave.service }}
  52. - require:
  53. - file: galera_bootstrap_temp_config
  54. galera_bootstrap_set_root_password:
  55. cmd.run:
  56. - name: mysqladmin password "{{ slave.admin.password }}"
  57. - require:
  58. - service: galera_bootstrap_start_service
  59. mysql_bootstrap_update_maint_password:
  60. cmd.run:
  61. - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
  62. - require:
  63. - cmd: galera_bootstrap_set_root_password
  64. galera_bootstrap_stop_service:
  65. service.dead:
  66. - name: {{ slave.service }}
  67. - require:
  68. - cmd: mysql_bootstrap_update_maint_password
  69. galera_bootstrap_init_config:
  70. file.managed:
  71. - name: {{ slave.config }}
  72. - source: salt://galera/files/my.cnf
  73. - mode: 644
  74. - template: jinja
  75. - require:
  76. - service: galera_bootstrap_stop_service
  77. galera_bootstrap_start_service_final:
  78. cmd.script:
  79. - name: slave_bootstrap
  80. - source: salt://galera/files/slave_bootstrap.sh
  81. - template: jinja
  82. - require:
  83. - file: galera_bootstrap_init_config
  84. galera_bootstrap_finish_flag:
  85. file.touch:
  86. - name: /root/.galera_bootstrap
  87. - require:
  88. - cmd: galera_bootstrap_start_service_final
  89. - watch_in:
  90. - file: galera_config
  91. {%- endif %}
  92. galera_config:
  93. file.managed:
  94. - name: {{ slave.config }}
  95. - source: salt://galera/files/my.cnf
  96. - mode: 644
  97. - template: jinja
  98. - require_in:
  99. - service: galera_service
  100. galera_service:
  101. service.running:
  102. - name: {{ slave.service }}
  103. - enable: true
  104. - reload: true
  105. {%- endif %}