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