blob: 303c282597952303c9cd1ce31c3de36722c3d029 [file] [log] [blame]
Jiri Broulik7e90fec2017-06-02 10:18:17 +02001/**
2 * Update packages on given nodes
3 *
4 * Expected parameters:
5 * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
6 * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000].
7 *
8**/
9
10def common = new com.mirantis.mk.Common()
11def salt = new com.mirantis.mk.Salt()
12
13
14def saltMaster
15
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040016node() {
Jiri Broulik7e90fec2017-06-02 10:18:17 +020017
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040018 stage('Connect to Salt API') {
19 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
20 }
21
22 stage('Start restore') {
23 // # actual upgrade
24
25 stage('Ask for manual confirmation') {
26 input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore mysql db?"
Jiri Broulik7e90fec2017-06-02 10:18:17 +020027 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040028 // database restore section
29 try {
30 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
31 } catch (Exception er) {
32 common.warningMsg('Mysql service already stopped')
Jiri Broulik7e90fec2017-06-02 10:18:17 +020033 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040034 try {
35 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true)
36 } catch (Exception er) {
37 common.warningMsg('Mysql service already stopped')
38 }
39 try {
40 salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
41 } catch (Exception er) {
42 common.warningMsg('Files are not present')
43 }
44 try {
45 salt.cmdRun(saltMaster, 'I@galera:master', "mkdir -p /root/mysql/mysql.bak")
46 } catch (Exception er) {
47 common.warningMsg('Directory already exists')
48 }
49 try {
50 salt.cmdRun(saltMaster, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
51 } catch (Exception er) {
52 common.warningMsg('Files were already moved')
53 }
54 try {
55 salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /var/lib/mysql/*")
56 } catch (Exception er) {
57 common.warningMsg('Directory already empty')
58 }
59 try {
60 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
61 } catch (Exception er) {
62 common.warningMsg('File is not present')
63 }
64 salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
65 _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir')
66 backup_dir = _pillar['return'][0].values()[0]
67 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
68 print(backup_dir)
69 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
70 salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
71 salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true)
72
73 // wait until mysql service on galera master is up
74 salt.commandStatus(saltMaster, 'I@galera:master', 'service mysql status', 'running')
75
76 salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Jiri Broulik3bf1d5c2017-08-11 12:31:37 +020077 try {
78 salt.commandStatus(saltMaster, 'I@galera:slave', 'service mysql status', 'running')
79 } catch (Exception er) {
80 common.warningMsg('Either there are no galera slaves or something failed when starting mysql on galera slaves')
81 }
82 sleep(5)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040083 salt.cmdRun(saltMaster, 'I@galera:master', "su root -c 'salt-call mysql.status | grep -A1 wsrep_cluster_size'")
Jiri Broulik7e90fec2017-06-02 10:18:17 +020084 }
85}