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.

121 lines
2.9KB

  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: '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: {{ master.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: {{ master.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: {{ master.service }}
  51. - require:
  52. - file: galera_bootstrap_temp_config
  53. galera_bootstrap_set_root_password:
  54. cmd.run:
  55. - name: mysqladmin password "{{ master.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{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';"
  61. - require:
  62. - cmd: galera_bootstrap_set_root_password
  63. galera_bootstrap_stop_service:
  64. service.dead:
  65. - name: {{ master.service }}
  66. - require:
  67. - cmd: mysql_bootstrap_update_maint_password
  68. galera_bootstrap_init_config:
  69. file.managed:
  70. - name: {{ master.config }}
  71. - source: salt://galera/files/my.cnf.init
  72. - mode: 644
  73. - template: jinja
  74. - require:
  75. - service: galera_bootstrap_stop_service
  76. galera_bootstrap_start_service_final:
  77. service.running:
  78. - name: {{ master.service }}
  79. - require:
  80. - file: galera_bootstrap_init_config
  81. galera_bootstrap_finish_flag:
  82. file.touch:
  83. - name: /root/.galera_bootstrap
  84. - require:
  85. - service: galera_bootstrap_start_service_final
  86. - watch_in:
  87. - file: galera_config
  88. {%- endif %}
  89. galera_config:
  90. file.managed:
  91. - name: {{ master.config }}
  92. - source: salt://galera/files/my.cnf
  93. - mode: 644
  94. - template: jinja
  95. - require_in:
  96. - service: galera_service
  97. galera_service:
  98. service.running:
  99. - name: {{ master.service }}
  100. - enable: true
  101. - reload: true
  102. {%- endif %}