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