Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 1 | {%- from "galera/map.jinja" import slave with context %} |
| 2 | {%- if slave.enabled %} |
| 3 | |
Filip Pytloun | da67965 | 2016-02-17 10:56:10 +0100 | [diff] [blame] | 4 | {%- if grains.os_family == 'RedHat' %} |
| 5 | xtrabackup_repo: |
| 6 | pkg.installed: |
| 7 | - sources: |
Filip Pytloun | d20f740 | 2016-02-17 11:01:00 +0100 | [diff] [blame] | 8 | - percona-release: {{ slave.xtrabackup_repo }} |
Filip Pytloun | da67965 | 2016-02-17 10:56:10 +0100 | [diff] [blame] | 9 | - require_in: |
| 10 | - pkg: galera_packages |
Filip Pytloun | 05b3e6d | 2016-02-17 12:59:45 +0100 | [diff] [blame] | 11 | |
| 12 | # Workaround https://bugs.launchpad.net/percona-server/+bug/1490144 |
| 13 | xtrabackup_repo_fix: |
| 14 | cmd.run: |
Filip Pytloun | 5a5324d | 2016-02-17 13:05:50 +0100 | [diff] [blame] | 15 | - name: | |
| 16 | sed -i 's,enabled\ =\ 1,enabled\ =\ 1\nexclude\ =\ Percona-XtraDB-\*\ Percona-Server-\*,g' /etc/yum.repos.d/percona-release.repo |
Filip Pytloun | 05b3e6d | 2016-02-17 12:59:45 +0100 | [diff] [blame] | 17 | - unless: 'grep "exclude = Percona-XtraDB-\*" /etc/yum.repos.d/percona-release.repo' |
| 18 | - watch: |
| 19 | - pkg: xtrabackup_repo |
| 20 | - require_in: |
| 21 | - pkg: galera_packages |
Filip Pytloun | da67965 | 2016-02-17 10:56:10 +0100 | [diff] [blame] | 22 | {%- endif %} |
| 23 | |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 24 | galera_packages: |
| 25 | pkg.installed: |
| 26 | - names: {{ slave.pkgs }} |
Filip Pytloun | d20f740 | 2016-02-17 11:01:00 +0100 | [diff] [blame] | 27 | - refresh: true |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 28 | |
| 29 | galera_log_dir: |
| 30 | file.directory: |
| 31 | - name: /var/log/mysql |
| 32 | - makedirs: true |
| 33 | - mode: 755 |
| 34 | - require: |
| 35 | - pkg: galera_packages |
| 36 | |
Filip Pytloun | a22a355 | 2015-07-21 17:54:59 +0200 | [diff] [blame] | 37 | {%- if grains.os_family == 'Debian' %} |
| 38 | galera_run_dir: |
| 39 | file.directory: |
| 40 | - name: /var/run/mysqld |
| 41 | - makedirs: true |
| 42 | - mode: 755 |
| 43 | - user: mysql |
| 44 | - group: root |
| 45 | - require: |
| 46 | - pkg: galera_packages |
Filip Pytloun | a22a355 | 2015-07-21 17:54:59 +0200 | [diff] [blame] | 47 | {%- endif %} |
| 48 | |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 49 | galera_init_script: |
| 50 | file.managed: |
| 51 | - name: /etc/init.d/mysql |
| 52 | - source: salt://galera/files/mysql |
| 53 | - mode: 755 |
| 54 | - require: |
| 55 | - pkg: galera_packages |
| 56 | |
Filip Pytloun | 9ba63ff | 2016-02-23 11:04:05 +0100 | [diff] [blame] | 57 | galera_bootstrap_script: |
| 58 | file.managed: |
| 59 | - name: /usr/local/sbin/galera_bootstrap.sh |
| 60 | - mode: 755 |
| 61 | - source: salt://galera/files/bootstrap.sh |
| 62 | - template: jinja |
| 63 | |
Jakub Pavlik | 4e4575f | 2015-09-01 22:05:52 +0200 | [diff] [blame] | 64 | {%- if salt['cmd.run']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %} |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 65 | |
| 66 | galera_bootstrap_temp_config: |
| 67 | file.managed: |
| 68 | - name: {{ slave.config }} |
| 69 | - source: salt://galera/files/my.cnf.bootstrap |
| 70 | - mode: 644 |
| 71 | - template: jinja |
| 72 | - require: |
| 73 | - pkg: galera_packages |
| 74 | - file: galera_init_script |
| 75 | |
| 76 | galera_bootstrap_start_service: |
Filip Pytloun | 9ba63ff | 2016-02-23 11:04:05 +0100 | [diff] [blame] | 77 | cmd.run: |
| 78 | - name: /usr/local/sbin/galera_bootstrap.sh |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 79 | - require: |
| 80 | - file: galera_bootstrap_temp_config |
Filip Pytloun | 52d29b5 | 2015-07-21 18:10:32 +0200 | [diff] [blame] | 81 | - file: galera_run_dir |
Filip Pytloun | 9ba63ff | 2016-02-23 11:04:05 +0100 | [diff] [blame] | 82 | - file: galera_bootstrap_script |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 83 | |
| 84 | galera_bootstrap_set_root_password: |
| 85 | cmd.run: |
| 86 | - name: mysqladmin password "{{ slave.admin.password }}" |
| 87 | - require: |
Jakub Pavlik | 4e4575f | 2015-09-01 22:05:52 +0200 | [diff] [blame] | 88 | - cmd: galera_bootstrap_start_service |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 89 | |
| 90 | mysql_bootstrap_update_maint_password: |
| 91 | cmd.run: |
| 92 | - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';" |
| 93 | - require: |
| 94 | - cmd: galera_bootstrap_set_root_password |
| 95 | |
| 96 | galera_bootstrap_stop_service: |
| 97 | service.dead: |
| 98 | - name: {{ slave.service }} |
| 99 | - require: |
| 100 | - cmd: mysql_bootstrap_update_maint_password |
| 101 | |
| 102 | galera_bootstrap_init_config: |
| 103 | file.managed: |
| 104 | - name: {{ slave.config }} |
| 105 | - source: salt://galera/files/my.cnf |
| 106 | - mode: 644 |
| 107 | - template: jinja |
| 108 | - require: |
| 109 | - service: galera_bootstrap_stop_service |
| 110 | |
| 111 | galera_bootstrap_start_service_final: |
Filip Pytloun | 9ba63ff | 2016-02-23 11:04:05 +0100 | [diff] [blame] | 112 | cmd.run: |
| 113 | - name: /usr/local/sbin/galera_bootstrap.sh |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 114 | - require: |
| 115 | - file: galera_bootstrap_init_config |
Filip Pytloun | 9ba63ff | 2016-02-23 11:04:05 +0100 | [diff] [blame] | 116 | - file: galera_bootstrap_script |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 117 | |
| 118 | galera_bootstrap_finish_flag: |
| 119 | file.touch: |
Jakub Pavlik | 4e4575f | 2015-09-01 22:05:52 +0200 | [diff] [blame] | 120 | - name: /var/lib/mysql/.galera_bootstrap |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 121 | - require: |
Ales Komarek | 2ff5486 | 2015-04-30 16:31:48 +0200 | [diff] [blame] | 122 | - cmd: galera_bootstrap_start_service_final |
Ales Komarek | 67ef806 | 2015-04-30 16:09:30 +0200 | [diff] [blame] | 123 | - watch_in: |
| 124 | - file: galera_config |
| 125 | |
| 126 | {%- endif %} |
| 127 | |
| 128 | galera_config: |
| 129 | file.managed: |
| 130 | - name: {{ slave.config }} |
| 131 | - source: salt://galera/files/my.cnf |
| 132 | - mode: 644 |
| 133 | - template: jinja |
| 134 | - require_in: |
| 135 | - service: galera_service |
| 136 | |
| 137 | galera_service: |
| 138 | service.running: |
| 139 | - name: {{ slave.service }} |
| 140 | - enable: true |
| 141 | - reload: true |
| 142 | |
Filip Pytloun | e40d54c | 2016-02-16 14:22:02 +0100 | [diff] [blame] | 143 | {%- endif %} |