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() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 12 | def python = new com.mirantis.mk.Python() |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 13 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 14 | def pepperEnv = "pepperEnv" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 15 | timeout(time: 12, unit: 'HOURS') { |
| 16 | node() { |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 17 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 18 | stage('Setup virtualenv for Pepper') { |
| 19 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 20 | } |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 21 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 22 | stage('Start restore') { |
| 23 | // # actual upgrade |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 24 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 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?" |
| 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 Tengler | feab8af | 2018-08-23 18:39:41 +0200 | [diff] [blame] | 70 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'state.apply', ["xtrabackup.client.restore"], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 71 | salt.runSaltProcessStep(pepperEnv, 'I@galera:master', 'service.start', ['mysql'], null, true) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 72 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 73 | // wait until mysql service on galera master is up |
| 74 | salt.commandStatus(pepperEnv, 'I@galera:master', 'service mysql status', 'running') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 75 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 76 | 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 Broulik | 715a3eb | 2018-06-18 10:59:52 +0200 | [diff] [blame] | 84 | |
| 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 Broulik | 3bf1d5c | 2017-08-11 12:31:37 +0200 | [diff] [blame] | 90 | } |
Jiri Broulik | 7e90fec | 2017-06-02 10:18:17 +0200 | [diff] [blame] | 91 | } |
| 92 | } |