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.

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