blob: b1d4a4e7be764bec0dffbb7f91ea4e5a08195caf [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()
chnyda625f4b42017-10-11 14:10:31 +020012def python = new com.mirantis.mk.Python()
Jiri Broulik7e90fec2017-06-02 10:18:17 +020013
chnyda625f4b42017-10-11 14:10:31 +020014def pepperEnv = "pepperEnv"
Jakub Josefa63f9862018-01-11 17:58:38 +010015timeout(time: 12, unit: 'HOURS') {
16 node() {
Jiri Broulik7e90fec2017-06-02 10:18:17 +020017
Jakub Josefa63f9862018-01-11 17:58:38 +010018 stage('Setup virtualenv for Pepper') {
19 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
20 }
Jiri Broulik7e90fec2017-06-02 10:18:17 +020021
Jakub Josefa63f9862018-01-11 17:58:38 +010022 stage('Start restore') {
23 // # actual upgrade
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040024
Jakub Josefa63f9862018-01-11 17:58:38 +010025 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?"
27 }
28 // database restore section
29 try {
30 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
31 } catch (Exception er) {
32 common.warningMsg('Mysql service already stopped')
33 }
34 try {
35 salt.runSaltProcessStep(pepperEnv, '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(pepperEnv, '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(pepperEnv, '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(pepperEnv, '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(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*")
56 } catch (Exception er) {
57 common.warningMsg('Directory already empty')
58 }
59 try {
60 salt.runSaltProcessStep(pepperEnv, '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(pepperEnv, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
65 _pillar = salt.getPillar(pepperEnv, "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(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
Adam Tenglerfeab8af2018-08-23 18:39:41 +020070 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'state.apply', ["xtrabackup.client.restore"], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010071 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040072
Jakub Josefa63f9862018-01-11 17:58:38 +010073 // wait until mysql service on galera master is up
74 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040075
Jakub Josefa63f9862018-01-11 17:58:38 +010076 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
77 try {
78 salt.commandStatus(pepperEnv, '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)
83 salt.cmdRun(pepperEnv, 'I@galera:master', "su root -c 'salt-call mysql.status | grep -A1 wsrep_cluster_size'")
Jiri Broulik715a3eb2018-06-18 10:59:52 +020084
85 try {
86 salt.runSaltProcessStep(pepperEnv, 'I@galera:master or I@galera:slave', 'file.touch', ["/var/lib/mysql/.galera_bootstrap"], null, true)
87 } catch (Exception er) {
88 common.warningMsg('File is already present')
89 }
Jiri Broulik3bf1d5c2017-08-11 12:31:37 +020090 }
Jiri Broulik7e90fec2017-06-02 10:18:17 +020091 }
92}