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