Saltstack Official Galera Formula
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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