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.3KB

  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 /var/lib/mysql/.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. cmd.script:
  64. - name: slave_initial_bootstrap
  65. - source: salt://galera/files/bootstrap.sh
  66. - template: jinja
  67. - require:
  68. - file: galera_bootstrap_temp_config
  69. - file: galera_run_dir
  70. galera_bootstrap_set_root_password:
  71. cmd.run:
  72. - name: mysqladmin password "{{ slave.admin.password }}"
  73. - require:
  74. - cmd: galera_bootstrap_start_service
  75. mysql_bootstrap_update_maint_password:
  76. cmd.run:
  77. - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
  78. - require:
  79. - cmd: galera_bootstrap_set_root_password
  80. galera_bootstrap_stop_service:
  81. service.dead:
  82. - name: {{ slave.service }}
  83. - require:
  84. - cmd: mysql_bootstrap_update_maint_password
  85. galera_bootstrap_init_config:
  86. file.managed:
  87. - name: {{ slave.config }}
  88. - source: salt://galera/files/my.cnf
  89. - mode: 644
  90. - template: jinja
  91. - require:
  92. - service: galera_bootstrap_stop_service
  93. galera_bootstrap_start_service_final:
  94. cmd.script:
  95. - name: slave_bootstrap
  96. - source: salt://galera/files/bootstrap.sh
  97. - template: jinja
  98. - require:
  99. - file: galera_bootstrap_init_config
  100. galera_bootstrap_finish_flag:
  101. file.touch:
  102. - name: /var/lib/mysql/.galera_bootstrap
  103. - require:
  104. - cmd: galera_bootstrap_start_service_final
  105. - watch_in:
  106. - file: galera_config
  107. {%- endif %}
  108. galera_config:
  109. file.managed:
  110. - name: {{ slave.config }}
  111. - source: salt://galera/files/my.cnf
  112. - mode: 644
  113. - template: jinja
  114. - require_in:
  115. - service: galera_service
  116. galera_service:
  117. service.running:
  118. - name: {{ slave.service }}
  119. - enable: true
  120. - reload: true
  121. {%- endif %}