blob: 1381d8286f137a710214ad1de1901fbf330cf20e [file] [log] [blame]
Ales Komarek67ef8062015-04-30 16:09:30 +02001{%- from "galera/map.jinja" import slave with context %}
2{%- if slave.enabled %}
3
4galera_packages:
5 pkg.installed:
6 - names: {{ slave.pkgs }}
7
8galera_log_dir:
9 file.directory:
10 - name: /var/log/mysql
11 - makedirs: true
12 - mode: 755
13 - require:
14 - pkg: galera_packages
15
16galera_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 Komarek651f9dd2015-04-30 16:41:19 +020024{%- if salt['cmd.run']('test -e /root/.galera_bootstrap; echo $?') != '0' %}
Ales Komarek67ef8062015-04-30 16:09:30 +020025
26galera_bootstrap_temp_config:
27 file.managed:
28 - name: {{ slave.config }}
29 - source: salt://galera/files/my.cnf.bootstrap
30 - mode: 644
31 - template: jinja
32 - require:
33 - pkg: galera_packages
34 - file: galera_init_script
35
36galera_bootstrap_start_service:
37 service.running:
38 - name: mysql
39 - require:
40 - file: galera_bootstrap_temp_config
41
42galera_bootstrap_set_root_password:
43 cmd.run:
44 - name: mysqladmin password "{{ slave.admin.password }}"
45 - require:
46 - service: galera_bootstrap_start_service
47
48mysql_bootstrap_update_maint_password:
49 cmd.run:
50 - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
51 - require:
52 - cmd: galera_bootstrap_set_root_password
53
54galera_bootstrap_stop_service:
55 service.dead:
56 - name: {{ slave.service }}
57 - require:
58 - cmd: mysql_bootstrap_update_maint_password
59
60galera_bootstrap_init_config:
61 file.managed:
62 - name: {{ slave.config }}
63 - source: salt://galera/files/my.cnf
64 - mode: 644
65 - template: jinja
66 - require:
67 - service: galera_bootstrap_stop_service
68
69galera_bootstrap_start_service_final:
Ales Komarek2ff54862015-04-30 16:31:48 +020070 cmd.script:
71 - name: slave_bootstrap
72 - source: salt://galera/files/slave_bootstrap.sh
Ales Komarek67ef8062015-04-30 16:09:30 +020073 - require:
74 - file: galera_bootstrap_init_config
75
76galera_bootstrap_finish_flag:
77 file.touch:
78 - name: /root/.galera_bootstrap
79 - require:
Ales Komarek2ff54862015-04-30 16:31:48 +020080 - cmd: galera_bootstrap_start_service_final
Ales Komarek67ef8062015-04-30 16:09:30 +020081 - watch_in:
82 - file: galera_config
83
84{%- endif %}
85
86galera_config:
87 file.managed:
88 - name: {{ slave.config }}
89 - source: salt://galera/files/my.cnf
90 - mode: 644
91 - template: jinja
92 - require_in:
93 - service: galera_service
94
95galera_service:
96 service.running:
97 - name: {{ slave.service }}
98 - enable: true
99 - reload: true
100
101{%- endif %}