Disable openstack-cinder-volume in step1 and reenable it in step2
[apex-tripleo-heat-templates.git] / extraconfig / tasks / major_upgrade_controller_pacemaker_1.sh
1 #!/bin/bash
2
3 set -eu
4
5 cluster_sync_timeout=1800
6
7 check_cluster
8 check_pcsd
9 check_clean_cluster
10 check_python_rpm
11 check_galera_root_password
12 check_disk_for_mysql_dump
13
14 # We want to disable fencing during the cluster --stop as it might fence
15 # nodes where a service fails to stop, which could be fatal during an upgrade
16 # procedure. So we remember the stonith state. If it was enabled we reenable it
17 # at the end of this script
18 STONITH_STATE=$(pcs property show stonith-enabled | grep "stonith-enabled" | awk '{ print $2 }')
19 pcs property set stonith-enabled=false
20
21 # Migrate to HA NG
22 if [ "$(hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid)" = "$(facter hostname)" ]; then
23     migrate_full_to_ng_ha
24 fi
25
26 # After migrating the cluster to HA-NG the services not under pacemaker's control
27 # are still up and running. We need to stop them explicitely otherwise during the yum
28 # upgrade the rpm %post sections will try to do a systemctl try-restart <service>, which
29 # is going to take a long time because rabbit is down. By having the service stopped
30 # systemctl try-restart is a noop
31
32 for $service in $(services_to_migrate); do
33     manage_systemd_service stop "${service%%-clone}"
34     check_resource_systemd "${service%%-clone}" stopped 600
35 done
36
37 # In case the mysql package is updated, the database on disk must be
38 # upgraded as well. This typically needs to happen during major
39 # version upgrades (e.g. 5.5 -> 5.6, 5.5 -> 10.1...)
40 #
41 # Because in-place upgrades are not supported across 2+ major versions
42 # (e.g. 5.5 -> 10.1), we rely on logical upgrades via dump/restore cycle
43 # https://bugzilla.redhat.com/show_bug.cgi?id=1341968
44 #
45 # The default is to determine automatically if upgrade is needed based
46 # on mysql package versionning, but this can be overriden manually
47 # to support specific upgrade scenario
48
49 if [ "$(hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid)" = "$(facter hostname)" ]; then
50     if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
51         mysqldump $backup_flags > "$MYSQL_BACKUP_DIR/openstack_database.sql"
52         cp -rdp /etc/my.cnf* "$MYSQL_BACKUP_DIR"
53     fi
54
55     pcs resource disable redis
56     check_resource redis stopped 600
57     pcs resource disable rabbitmq
58     check_resource rabbitmq stopped 600
59     pcs resource disable galera
60     check_resource galera stopped 600
61     pcs resource disable openstack-cinder-volume
62     check_resource openstack-cinder-volume stopped 600
63     # Disable all VIPs before stopping the cluster, so that pcs doesn't use one as a source address:
64     #   https://bugzilla.redhat.com/show_bug.cgi?id=1330688
65     for vip in $(pcs resource show | grep ocf::heartbeat:IPaddr2 | grep Started | awk '{ print $1 }'); do
66       pcs resource disable $vip
67       check_resource $vip stopped 60
68     done
69     pcs cluster stop --all
70 fi
71
72
73 # Swift isn't controled by pacemaker
74 systemctl_swift stop
75
76 tstart=$(date +%s)
77 while systemctl is-active pacemaker; do
78     sleep 5
79     tnow=$(date +%s)
80     if (( tnow-tstart > cluster_sync_timeout )) ; then
81         echo_error "ERROR: cluster shutdown timed out"
82         exit 1
83     fi
84 done
85
86 # The reason we do an sql dump *and* we move the old dir out of
87 # the way is because it gives us an extra level of safety in case
88 # something goes wrong during the upgrade. Once the restore is
89 # successful we go ahead and remove it. If the directory exists
90 # we bail out as it means the upgrade process had issues in the last
91 # run.
92 if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
93     if [ -d $MYSQL_TEMP_UPGRADE_BACKUP_DIR ]; then
94         echo_error "ERROR: mysql backup dir already exist"
95         exit 1
96     fi
97     mv /var/lib/mysql $MYSQL_TEMP_UPGRADE_BACKUP_DIR
98 fi
99
100 yum -y install python-zaqarclient  # needed for os-collect-config
101 yum -y -q update
102
103 # We need to ensure at least those two configuration settings, otherwise
104 # mariadb 10.1+ won't activate galera replication.
105 # wsrep_cluster_address must only be set though, its value does not
106 # matter because it's overriden by the galera resource agent.
107 cat >> /etc/my.cnf.d/galera.cnf <<EOF
108 [mysqld]
109 wsrep_on = ON
110 wsrep_cluster_address = gcomm://localhost
111 EOF
112
113 if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
114     # Scripts run via heat have no HOME variable set and this confuses
115     # mysqladmin
116     export HOME=/root
117
118     mkdir /var/lib/mysql || /bin/true
119     chown mysql:mysql /var/lib/mysql
120     chmod 0755 /var/lib/mysql
121     restorecon -R /var/lib/mysql/
122     mysql_install_db --datadir=/var/lib/mysql --user=mysql
123     chown -R mysql:mysql /var/lib/mysql/
124
125     if [ "$(hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid)" = "$(facter hostname)" ]; then
126         mysqld_safe --wsrep-new-cluster &
127         # We have a populated /root/.my.cnf with root/password here so
128         # we need to temporarily rename it because the newly created
129         # db is empty and no root password is set
130         mv /root/.my.cnf /root/.my.cnf.temporary
131         timeout 60 sh -c 'while ! mysql -e "" &> /dev/null; do sleep 1; done'
132         mysql -u root < "$MYSQL_BACKUP_DIR/openstack_database.sql"
133         mv /root/.my.cnf.temporary /root/.my.cnf
134         mysqladmin -u root shutdown
135         # The import was successful so we may remove the folder
136         rm -r "$MYSQL_BACKUP_DIR"
137     fi
138 fi
139
140 # If we reached here without error we can safely blow away the origin
141 # mysql dir from every controller
142
143 # TODO: What if the upgrade fails on the bootstrap node, but not on
144 # this controller.  Data may be lost.
145 if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
146     rm -r $MYSQL_TEMP_UPGRADE_BACKUP_DIR
147 fi
148
149 # Let's reset the stonith back to true if it was true, before starting the cluster
150 if [ $STONITH_STATE == "true" ]; then
151     pcs -f /var/lib/pacemaker/cib/cib.xml property set stonith-enabled=true
152 fi
153
154 # Pin messages sent to compute nodes to kilo, these will be upgraded later
155 crudini  --set /etc/nova/nova.conf upgrade_levels compute "$upgrade_level_nova_compute"
156
157 crudini --set /etc/sahara/sahara.conf DEFAULT plugins ambari,cdh,mapr,vanilla,spark,storm