blob: 4b5e6f23538630d9bd238ff2c08c246ae5066acc [file] [log] [blame]
Ales Komarek67ef8062015-04-30 16:09:30 +02001{%- from "galera/map.jinja" import slave with context %}
2{%- if slave.enabled %}
3
Filip Pytlounda679652016-02-17 10:56:10 +01004{%- if grains.os_family == 'RedHat' %}
5xtrabackup_repo:
6 pkg.installed:
7 - sources:
Filip Pytlound20f7402016-02-17 11:01:00 +01008 - percona-release: {{ slave.xtrabackup_repo }}
Filip Pytlounda679652016-02-17 10:56:10 +01009 - require_in:
10 - pkg: galera_packages
Filip Pytloun05b3e6d2016-02-17 12:59:45 +010011
12# Workaround https://bugs.launchpad.net/percona-server/+bug/1490144
13xtrabackup_repo_fix:
14 cmd.run:
Filip Pytloun5a5324d2016-02-17 13:05:50 +010015 - name: |
16 sed -i 's,enabled\ =\ 1,enabled\ =\ 1\nexclude\ =\ Percona-XtraDB-\*\ Percona-Server-\*,g' /etc/yum.repos.d/percona-release.repo
Filip Pytloun05b3e6d2016-02-17 12:59:45 +010017 - 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 Pytlounda679652016-02-17 10:56:10 +010022{%- endif %}
23
Ales Komarek67ef8062015-04-30 16:09:30 +020024galera_packages:
25 pkg.installed:
26 - names: {{ slave.pkgs }}
Filip Pytlound20f7402016-02-17 11:01:00 +010027 - refresh: true
Ales Komarek67ef8062015-04-30 16:09:30 +020028
29galera_log_dir:
30 file.directory:
31 - name: /var/log/mysql
32 - makedirs: true
33 - mode: 755
34 - require:
35 - pkg: galera_packages
36
Filip Pytlouna22a3552015-07-21 17:54:59 +020037{%- if grains.os_family == 'Debian' %}
38galera_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
47 - require_in:
48 - service: galera_bootstrap_start_service
49{%- endif %}
50
Ales Komarek67ef8062015-04-30 16:09:30 +020051galera_init_script:
52 file.managed:
53 - name: /etc/init.d/mysql
54 - source: salt://galera/files/mysql
55 - mode: 755
56 - require:
57 - pkg: galera_packages
58
Jakub Pavlik4e4575f2015-09-01 22:05:52 +020059{%- if salt['cmd.run']('test -e /var/lib/mysql/.galera_bootstrap; echo $?') != '0' %}
Ales Komarek67ef8062015-04-30 16:09:30 +020060
61galera_bootstrap_temp_config:
62 file.managed:
63 - name: {{ slave.config }}
64 - source: salt://galera/files/my.cnf.bootstrap
65 - mode: 644
66 - template: jinja
67 - require:
68 - pkg: galera_packages
69 - file: galera_init_script
70
71galera_bootstrap_start_service:
Jakub Pavlik4e4575f2015-09-01 22:05:52 +020072 cmd.script:
73 - name: slave_initial_bootstrap
74 - source: salt://galera/files/bootstrap.sh
75 - template: jinja
Ales Komarek67ef8062015-04-30 16:09:30 +020076 - require:
77 - file: galera_bootstrap_temp_config
Filip Pytloun52d29b52015-07-21 18:10:32 +020078 - file: galera_run_dir
Ales Komarek67ef8062015-04-30 16:09:30 +020079
80galera_bootstrap_set_root_password:
81 cmd.run:
82 - name: mysqladmin password "{{ slave.admin.password }}"
83 - require:
Jakub Pavlik4e4575f2015-09-01 22:05:52 +020084 - cmd: galera_bootstrap_start_service
Ales Komarek67ef8062015-04-30 16:09:30 +020085
86mysql_bootstrap_update_maint_password:
87 cmd.run:
88 - name: mysql -u root -p{{ slave.admin.password }} -e "GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '{{ slave.maintenance_password }}';"
89 - require:
90 - cmd: galera_bootstrap_set_root_password
91
92galera_bootstrap_stop_service:
93 service.dead:
94 - name: {{ slave.service }}
95 - require:
96 - cmd: mysql_bootstrap_update_maint_password
97
98galera_bootstrap_init_config:
99 file.managed:
100 - name: {{ slave.config }}
101 - source: salt://galera/files/my.cnf
102 - mode: 644
103 - template: jinja
104 - require:
105 - service: galera_bootstrap_stop_service
106
107galera_bootstrap_start_service_final:
Ales Komarek2ff54862015-04-30 16:31:48 +0200108 cmd.script:
109 - name: slave_bootstrap
Jakub Pavlik4e4575f2015-09-01 22:05:52 +0200110 - source: salt://galera/files/bootstrap.sh
Filip Pytloun52d29b52015-07-21 18:10:32 +0200111 - template: jinja
Ales Komarek67ef8062015-04-30 16:09:30 +0200112 - require:
113 - file: galera_bootstrap_init_config
114
115galera_bootstrap_finish_flag:
116 file.touch:
Jakub Pavlik4e4575f2015-09-01 22:05:52 +0200117 - name: /var/lib/mysql/.galera_bootstrap
Ales Komarek67ef8062015-04-30 16:09:30 +0200118 - require:
Ales Komarek2ff54862015-04-30 16:31:48 +0200119 - cmd: galera_bootstrap_start_service_final
Ales Komarek67ef8062015-04-30 16:09:30 +0200120 - watch_in:
121 - file: galera_config
122
123{%- endif %}
124
125galera_config:
126 file.managed:
127 - name: {{ slave.config }}
128 - source: salt://galera/files/my.cnf
129 - mode: 644
130 - template: jinja
131 - require_in:
132 - service: galera_service
133
134galera_service:
135 service.running:
136 - name: {{ slave.service }}
137 - enable: true
138 - reload: true
139
Filip Pytloune40d54c2016-02-16 14:22:02 +0100140{%- endif %}