Merge "Full HA->HA NG migration might fail setting maintenance-mode"
[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 [[ -n $(is_bootstrap_node) ]]; 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     # So the reason for not reusing check_resource_systemd is that
35     # I have observed systemctl is-active returning unknown with at least
36     # one service that was stopped (See LP 1627254)
37     timeout=600
38     tstart=$(date +%s)
39     tend=$(( $tstart + $timeout ))
40     check_interval=3
41     while (( $(date +%s) < $tend )); do
42       if [[ "$(systemctl is-active ${service%%-clone})" = "active" ]]; then
43         echo "$service still active, sleeping $check_interval seconds."
44         sleep $check_interval
45       else
46         # we do not care if it is inactive, unknown or failed as long as it is
47         # not running
48         break
49       fi
50
51     done
52 done
53
54 # In case the mysql package is updated, the database on disk must be
55 # upgraded as well. This typically needs to happen during major
56 # version upgrades (e.g. 5.5 -> 5.6, 5.5 -> 10.1...)
57 #
58 # Because in-place upgrades are not supported across 2+ major versions
59 # (e.g. 5.5 -> 10.1), we rely on logical upgrades via dump/restore cycle
60 # https://bugzilla.redhat.com/show_bug.cgi?id=1341968
61 #
62 # The default is to determine automatically if upgrade is needed based
63 # on mysql package versionning, but this can be overriden manually
64 # to support specific upgrade scenario
65
66 if [[ -n $(is_bootstrap_node) ]]; then
67     if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
68         mysqldump $backup_flags > "$MYSQL_BACKUP_DIR/openstack_database.sql"
69         cp -rdp /etc/my.cnf* "$MYSQL_BACKUP_DIR"
70     fi
71
72     pcs resource disable redis
73     check_resource redis stopped 600
74     pcs resource disable rabbitmq
75     check_resource rabbitmq stopped 600
76     pcs resource disable galera
77     check_resource galera stopped 600
78     pcs resource disable openstack-cinder-volume
79     check_resource openstack-cinder-volume stopped 600
80     # Disable all VIPs before stopping the cluster, so that pcs doesn't use one as a source address:
81     #   https://bugzilla.redhat.com/show_bug.cgi?id=1330688
82     for vip in $(pcs resource show | grep ocf::heartbeat:IPaddr2 | grep Started | awk '{ print $1 }'); do
83       pcs resource disable $vip
84       check_resource $vip stopped 60
85     done
86     pcs cluster stop --all
87 fi
88
89
90 # Swift isn't controlled by pacemaker
91 systemctl_swift stop
92
93 tstart=$(date +%s)
94 while systemctl is-active pacemaker; do
95     sleep 5
96     tnow=$(date +%s)
97     if (( tnow-tstart > cluster_sync_timeout )) ; then
98         echo_error "ERROR: cluster shutdown timed out"
99         exit 1
100     fi
101 done
102
103 # The reason we do an sql dump *and* we move the old dir out of
104 # the way is because it gives us an extra level of safety in case
105 # something goes wrong during the upgrade. Once the restore is
106 # successful we go ahead and remove it. If the directory exists
107 # we bail out as it means the upgrade process had issues in the last
108 # run.
109 if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
110     if [ -d $MYSQL_TEMP_UPGRADE_BACKUP_DIR ]; then
111         echo_error "ERROR: mysql backup dir already exist"
112         exit 1
113     fi
114     mv /var/lib/mysql $MYSQL_TEMP_UPGRADE_BACKUP_DIR
115 fi
116
117 yum -y install python-zaqarclient  # needed for os-collect-config
118 yum -y -q update
119
120 # We need to ensure at least those two configuration settings, otherwise
121 # mariadb 10.1+ won't activate galera replication.
122 # wsrep_cluster_address must only be set though, its value does not
123 # matter because it's overriden by the galera resource agent.
124 cat >> /etc/my.cnf.d/galera.cnf <<EOF
125 [mysqld]
126 wsrep_on = ON
127 wsrep_cluster_address = gcomm://localhost
128 EOF
129
130 if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
131     # Scripts run via heat have no HOME variable set and this confuses
132     # mysqladmin
133     export HOME=/root
134
135     mkdir /var/lib/mysql || /bin/true
136     chown mysql:mysql /var/lib/mysql
137     chmod 0755 /var/lib/mysql
138     restorecon -R /var/lib/mysql/
139     mysql_install_db --datadir=/var/lib/mysql --user=mysql
140     chown -R mysql:mysql /var/lib/mysql/
141
142     if [ "$(hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid)" = "$(facter hostname)" ]; then
143         mysqld_safe --wsrep-new-cluster &
144         # We have a populated /root/.my.cnf with root/password here so
145         # we need to temporarily rename it because the newly created
146         # db is empty and no root password is set
147         mv /root/.my.cnf /root/.my.cnf.temporary
148         timeout 60 sh -c 'while ! mysql -e "" &> /dev/null; do sleep 1; done'
149         mysql -u root < "$MYSQL_BACKUP_DIR/openstack_database.sql"
150         mv /root/.my.cnf.temporary /root/.my.cnf
151         mysqladmin -u root shutdown
152         # The import was successful so we may remove the folder
153         rm -r "$MYSQL_BACKUP_DIR"
154     fi
155 fi
156
157 # If we reached here without error we can safely blow away the origin
158 # mysql dir from every controller
159
160 # TODO: What if the upgrade fails on the bootstrap node, but not on
161 # this controller.  Data may be lost.
162 if [ $DO_MYSQL_UPGRADE -eq 1 ]; then
163     rm -r $MYSQL_TEMP_UPGRADE_BACKUP_DIR
164 fi
165
166 # Let's reset the stonith back to true if it was true, before starting the cluster
167 if [ $STONITH_STATE == "true" ]; then
168     pcs -f /var/lib/pacemaker/cib/cib.xml property set stonith-enabled=true
169 fi
170
171 # Pin messages sent to compute nodes to kilo, these will be upgraded later
172 crudini  --set /etc/nova/nova.conf upgrade_levels compute "$upgrade_level_nova_compute"
173 # https://bugzilla.redhat.com/show_bug.cgi?id=1284047
174 # Change-Id: Ib3f6c12ff5471e1f017f28b16b1e6496a4a4b435
175 crudini  --set /etc/ceilometer/ceilometer.conf DEFAULT rpc_backend rabbit
176 # https://bugzilla.redhat.com/show_bug.cgi?id=1284058
177 # Ifd1861e3df46fad0e44ff9b5cbd58711bbc87c97 Swift Ceilometer middleware no longer exists
178 crudini --set /etc/swift/proxy-server.conf pipeline:main pipeline "catch_errors healthcheck cache ratelimit tempurl formpost authtoken keystone staticweb proxy-logging proxy-server"
179 # LP: 1615035, required only for M/N upgrade.
180 crudini --set /etc/nova/nova.conf DEFAULT scheduler_host_manager host_manager
181 # LP: 1627450, required only for M/N upgrade
182 crudini --set /etc/nova/nova.conf DEFAULT scheduler_driver filter_scheduler
183
184 crudini --set /etc/sahara/sahara.conf DEFAULT plugins ambari,cdh,mapr,vanilla,spark,storm