Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 1 | {%- from "galera/map.jinja" import master with context %} |
| 2 | {%- if master.enabled %} |
| 3 | |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 4 | galera_packages: |
| 5 | pkg.installed: |
| 6 | - names: {{ master.pkgs }} |
| 7 | |
| 8 | galera_log_dir: |
| 9 | file.directory: |
| 10 | - name: /var/log/mysql |
| 11 | - makedirs: true |
| 12 | - mode: 755 |
| 13 | - require: |
| 14 | - pkg: galera_packages |
| 15 | |
Ales Komarek | 90da78d | 2015-04-30 16:01:11 +0200 | [diff] [blame] | 16 | galera_init_script: |
| 17 | file.managed: |
| 18 | - name: /etc/init.d/mysql |
| 19 | - source: salt://galera/files/mysql |
| 20 | - mode: 755 |
| 21 | - require: |
| 22 | - pkg: galera_packages |
| 23 | |
Ales Komarek | cf92b4e | 2015-04-30 16:52:21 +0200 | [diff] [blame] | 24 | {%- if salt['cmd.run']('test -e /root/.galera_bootstrap; echo $?') != '0' %} |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 25 | |
| 26 | galera_bootstrap_temp_config: |
| 27 | file.managed: |
| 28 | - name: {{ master.config }} |
Ales Komarek | 1fe9c70 | 2015-04-30 15:46:37 +0200 | [diff] [blame] | 29 | - source: salt://galera/files/my.cnf.bootstrap |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 30 | - mode: 644 |
| 31 | - template: jinja |
| 32 | - require: |
| 33 | - pkg: galera_packages |
Ales Komarek | 90da78d | 2015-04-30 16:01:11 +0200 | [diff] [blame] | 34 | - file: galera_init_script |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 35 | |
| 36 | galera_bootstrap_start_service: |
| 37 | service.running: |
| 38 | - name: mysql |
| 39 | - require: |
| 40 | - file: galera_bootstrap_temp_config |
| 41 | |
| 42 | galera_bootstrap_set_root_password: |
| 43 | cmd.run: |
| 44 | - name: mysqladmin password "{{ master.admin.password }}" |
| 45 | - require: |
| 46 | - service: galera_bootstrap_start_service |
| 47 | |
| 48 | mysql_bootstrap_update_maint_password: |
| 49 | cmd.run: |
| 50 | - name: mysql -u root -p{{ master.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ master.maintenance_password }}';" |
| 51 | - require: |
| 52 | - cmd: galera_bootstrap_set_root_password |
| 53 | |
Ales Komarek | 41517c4 | 2015-04-30 15:58:19 +0200 | [diff] [blame] | 54 | galera_bootstrap_stop_service: |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 55 | service.dead: |
Ales Komarek | 41517c4 | 2015-04-30 15:58:19 +0200 | [diff] [blame] | 56 | - name: {{ master.service }} |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 57 | - require: |
| 58 | - cmd: mysql_bootstrap_update_maint_password |
| 59 | |
| 60 | galera_bootstrap_init_config: |
| 61 | file.managed: |
| 62 | - name: {{ master.config }} |
Ales Komarek | 41517c4 | 2015-04-30 15:58:19 +0200 | [diff] [blame] | 63 | - source: salt://galera/files/my.cnf.init |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 64 | - mode: 644 |
| 65 | - template: jinja |
| 66 | - require: |
| 67 | - service: galera_bootstrap_stop_service |
| 68 | |
Ales Komarek | 41517c4 | 2015-04-30 15:58:19 +0200 | [diff] [blame] | 69 | galera_bootstrap_start_service_final: |
| 70 | service.running: |
| 71 | - name: {{ master.service }} |
| 72 | - require: |
| 73 | - file: galera_bootstrap_init_config |
| 74 | |
Ales Komarek | b282410 | 2015-04-30 15:43:17 +0200 | [diff] [blame] | 75 | galera_bootstrap_finish_flag: |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 76 | file.touch: |
Ales Komarek | 22a43f5 | 2015-04-30 16:03:27 +0200 | [diff] [blame] | 77 | - name: /root/.galera_bootstrap |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 78 | - require: |
Ales Komarek | 41517c4 | 2015-04-30 15:58:19 +0200 | [diff] [blame] | 79 | - service: galera_bootstrap_start_service_final |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 80 | - watch_in: |
Ales Komarek | 41517c4 | 2015-04-30 15:58:19 +0200 | [diff] [blame] | 81 | - file: galera_config |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 82 | |
| 83 | {%- endif %} |
| 84 | |
Ales Komarek | 41517c4 | 2015-04-30 15:58:19 +0200 | [diff] [blame] | 85 | galera_config: |
| 86 | file.managed: |
| 87 | - name: {{ master.config }} |
| 88 | - source: salt://galera/files/my.cnf |
| 89 | - mode: 644 |
| 90 | - template: jinja |
| 91 | - require_in: |
| 92 | - service: galera_service |
| 93 | |
Ales Komarek | cba48ac | 2015-04-30 11:40:44 +0200 | [diff] [blame] | 94 | galera_service: |
| 95 | service.running: |
| 96 | - name: {{ master.service }} |
| 97 | - enable: true |
| 98 | - reload: true |
| 99 | |
| 100 | {%- endif %} |