Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 1 | /** |
| 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 | |
| 10 | def common = new com.mirantis.mk.Common() |
| 11 | def salt = new com.mirantis.mk.Salt() |
| 12 | |
| 13 | |
| 14 | def saltMaster |
| 15 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 16 | node() { |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 17 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 18 | 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 Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 27 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 28 | // 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 Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 33 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 34 | 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 Broulik | 3bf1d5c | 2017-08-11 12:31:37 +0200 | [diff] [blame] | 77 | 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 Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 83 | salt.cmdRun(saltMaster, 'I@galera:master', "su root -c 'salt-call mysql.status | grep -A1 wsrep_cluster_size'") |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 84 | } |
| 85 | } |