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