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.

138 lines
3.2KB

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