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