blob: 50b2bcefc48a029334538534972bd821f03c7e5f [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"
Jiri Broulik7e90fec2017-06-02 10:18:17 +020015
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040016node() {
Jiri Broulik7e90fec2017-06-02 10:18:17 +020017
chnyda625f4b42017-10-11 14:10:31 +020018 stage('Setup virtualenv for Pepper') {
Dmitrii Kabanovf31c8962017-10-12 21:00:30 -070019 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040020 }
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 {
chnyda625f4b42017-10-11 14:10:31 +020030 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040031 } 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 {
chnyda625f4b42017-10-11 14:10:31 +020035 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.stop', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040036 } catch (Exception er) {
37 common.warningMsg('Mysql service already stopped')
38 }
39 try {
chnyda625f4b42017-10-11 14:10:31 +020040 salt.cmdRun(pepperEnv, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040041 } catch (Exception er) {
42 common.warningMsg('Files are not present')
43 }
44 try {
chnyda625f4b42017-10-11 14:10:31 +020045 salt.cmdRun(pepperEnv, 'I@galera:master', "mkdir -p /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040046 } catch (Exception er) {
47 common.warningMsg('Directory already exists')
48 }
49 try {
chnyda625f4b42017-10-11 14:10:31 +020050 salt.cmdRun(pepperEnv, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040051 } catch (Exception er) {
52 common.warningMsg('Files were already moved')
53 }
54 try {
chnyda625f4b42017-10-11 14:10:31 +020055 salt.cmdRun(pepperEnv, 'I@galera:master', "rm -rf /var/lib/mysql/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040056 } catch (Exception er) {
57 common.warningMsg('Directory already empty')
58 }
59 try {
chnyda625f4b42017-10-11 14:10:31 +020060 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040061 } catch (Exception er) {
62 common.warningMsg('File is not present')
63 }
chnyda625f4b42017-10-11 14:10:31 +020064 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')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040066 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)
chnyda625f4b42017-10-11 14:10:31 +020069 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
70 salt.cmdRun(pepperEnv, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
71 salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040072
73 // wait until mysql service on galera master is up
chnyda625f4b42017-10-11 14:10:31 +020074 salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040075
chnyda625f4b42017-10-11 14:10:31 +020076 salt.runSaltProcessStep(pepperEnv, 'I@galera:slave', 'service.start', ['mysql'], null, true)
Jiri Broulik3bf1d5c2017-08-11 12:31:37 +020077 try {
chnyda625f4b42017-10-11 14:10:31 +020078 salt.commandStatus(pepperEnv, 'I@galera:slave', 'service mysql status', 'running')
Jiri Broulik3bf1d5c2017-08-11 12:31:37 +020079 } 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)
chnyda625f4b42017-10-11 14:10:31 +020083 salt.cmdRun(pepperEnv, 'I@galera:master', "su root -c 'salt-call mysql.status | grep -A1 wsrep_cluster_size'")
Jiri Broulik7e90fec2017-06-02 10:18:17 +020084 }
85}