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 | |
| 16 | timestamps { |
| 17 | node() { |
| 18 | |
| 19 | stage('Connect to Salt API') { |
| 20 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 21 | } |
| 22 | |
| 23 | stage('Start restore') { |
| 24 | // # actual upgrade |
| 25 | |
| 26 | stage('Ask for manual confirmation') { |
| 27 | input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore mysql db?" |
| 28 | } |
| 29 | // database restore section |
| 30 | try { |
| 31 | salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.stop', ['mysql'], null, true) |
| 32 | } catch (Exception er) { |
| 33 | common.warningMsg('Mysql service already stopped') |
| 34 | } |
| 35 | try { |
| 36 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.stop', ['mysql'], null, true) |
| 37 | } catch (Exception er) { |
| 38 | common.warningMsg('Mysql service already stopped') |
| 39 | } |
| 40 | try { |
| 41 | salt.cmdRun(saltMaster, 'I@galera:slave', "rm /var/lib/mysql/ib_logfile*") |
| 42 | } catch (Exception er) { |
| 43 | common.warningMsg('Files are not present') |
| 44 | } |
| 45 | try { |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame^] | 46 | salt.cmdRun(saltMaster, 'I@galera:master', "mkdir -p /root/mysql/mysql.bak") |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 47 | } catch (Exception er) { |
| 48 | common.warningMsg('Directory already exists') |
| 49 | } |
| 50 | try { |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 51 | salt.cmdRun(saltMaster, 'I@galera:master', "mv /var/lib/mysql/* /root/mysql/mysql.bak") |
| 52 | } catch (Exception er) { |
| 53 | common.warningMsg('Files were already moved') |
| 54 | } |
| 55 | try { |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame^] | 56 | salt.cmdRun(saltMaster, 'I@galera:master', "rm -rf /var/lib/mysql/*") |
| 57 | } catch (Exception er) { |
| 58 | common.warningMsg('Directory already empty') |
| 59 | } |
| 60 | try { |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 61 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["/var/lib/mysql/.galera_bootstrap"], null, true) |
| 62 | } catch (Exception er) { |
| 63 | common.warningMsg('File is not present') |
| 64 | } |
| 65 | salt.cmdRun(saltMaster, 'I@galera:master', "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf") |
| 66 | _pillar = salt.getPillar(saltMaster, "I@galera:master", 'xtrabackup:client:backup_dir') |
| 67 | backup_dir = _pillar['return'][0].values()[0] |
| 68 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' } |
| 69 | print(backup_dir) |
| 70 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
| 71 | salt.cmdRun(saltMaster, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'") |
| 72 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'service.start', ['mysql'], null, true) |
| 73 | sleep(5) |
| 74 | salt.runSaltProcessStep(saltMaster, 'I@galera:slave', 'service.start', ['mysql'], null, true) |
| 75 | sleep(15) |
| 76 | salt.cmdRun(saltMaster, 'I@galera:master', "su root -c 'salt-call mysql.status | grep -A1 wsrep_cluster_size'") |
| 77 | |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | |
| 83 | |