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