Merge "Remove special-case of memcache node ips for ipv6"
[apex-tripleo-heat-templates.git] / extraconfig / tasks / yum_update.sh
1 #!/bin/bash
2
3 # A heat-config-script which runs yum update during a stack-update.
4 # Inputs:
5 #   deploy_action - yum will only be run if this is UPDATE
6 #   update_identifier - yum will only run for previously unused values of update_identifier
7 #   command - yum sub-command to run, defaults to "update"
8 #   command_arguments - yum command arguments, defaults to ""
9
10 echo "Started yum_update.sh on server $deploy_server_id at `date`"
11 echo -n "false" > $heat_outputs_path.update_managed_packages
12
13 if [ -f /.dockerenv ]; then
14     echo "Not running due to running inside a container"
15     exit 0
16 fi
17
18 if [[ -z "$update_identifier" ]]; then
19     echo "Not running due to unset update_identifier"
20     exit 0
21 fi
22
23 timestamp_dir=/var/lib/overcloud-yum-update
24 mkdir -p $timestamp_dir
25
26 # sanitise to remove unusual characters
27 update_identifier=${update_identifier//[^a-zA-Z0-9-_]/}
28
29 # seconds to wait for this node to rejoin the cluster after update
30 cluster_start_timeout=600
31 galera_sync_timeout=1800
32 cluster_settle_timeout=1800
33
34 timestamp_file="$timestamp_dir/$update_identifier"
35 if [[ -a "$timestamp_file" ]]; then
36     echo "Not running for already-run timestamp \"$update_identifier\""
37     exit 0
38 fi
39 touch "$timestamp_file"
40
41 pacemaker_status=""
42 # We include word boundaries in order to not match pacemaker_remote
43 if hiera -c /etc/puppet/hiera.yaml service_names | grep -q '\bpacemaker\b'; then
44     pacemaker_status=$(systemctl is-active pacemaker)
45 fi
46
47 # (NB: when backporting this s/pacemaker_short_bootstrap_node_name/bootstrap_nodeid)
48 # This runs before the yum_update so we are guaranteed to run it even in the absence
49 # of packages to update (the check for -z "$update_identifier" guarantees that this
50 # is run only on overcloud stack update -i)
51 if [[ "$pacemaker_status" == "active" && \
52         "$(hiera -c /etc/puppet/hiera.yaml pacemaker_short_bootstrap_node_name | tr '[:upper:]' '[:lower:]')" == "$(facter hostname | tr '[:upper:]' '[:lower:]')" ]] ; then \
53     # OCF scripts don't cope with -eu
54     echo "Verifying if we need to fix up any IPv6 VIPs"
55     set +eu
56     fixup_wrong_ipv6_vip
57     ret=$?
58     set -eu
59     if [ $ret -ne 0 ]; then
60         echo "Fixing up IPv6 VIPs failed. Stopping here. (See https://bugs.launchpad.net/tripleo/+bug/1686357 for more info)"
61         exit 1
62     fi
63 fi
64
65 command_arguments=${command_arguments:-}
66
67 # yum check-update exits 100 if updates are available
68 set +e
69 check_update=$(yum check-update 2>&1)
70 check_update_exit=$?
71 set -e
72
73 if [[ "$check_update_exit" == "1" ]]; then
74     echo "Failed to check for package updates"
75     echo "$check_update"
76     exit 1
77 elif [[ "$check_update_exit" != "100" ]]; then
78     echo "No packages require updating"
79     exit 0
80 fi
81
82 # special case https://bugs.launchpad.net/tripleo/+bug/1635205 +bug/1669714
83 special_case_ovs_upgrade_if_needed
84
85 if [[ "$pacemaker_status" == "active" ]] ; then
86     echo "Pacemaker running, stopping cluster node and doing full package update"
87     node_count=$(pcs status xml | grep -o "<nodes_configured.*/>" | grep -o 'number="[0-9]*"' | grep -o "[0-9]*")
88     if [[ "$node_count" == "1" ]] ; then
89         echo "Active node count is 1, stopping node with --force"
90         pcs cluster stop --force
91     else
92         pcs cluster stop
93     fi
94 else
95     echo "Upgrading openstack-puppet-modules and its dependencies"
96     check_for_yum_lock
97     yum -q -y update openstack-puppet-modules
98     yum deplist openstack-puppet-modules | awk '/dependency/{print $2}' | xargs yum -q -y update
99     echo "Upgrading other packages is handled by config management tooling"
100     echo -n "true" > $heat_outputs_path.update_managed_packages
101     exit 0
102 fi
103
104 command=${command:-update}
105 full_command="yum -q -y $command $command_arguments"
106
107 echo "Running: $full_command"
108 check_for_yum_lock
109 result=$($full_command)
110 return_code=$?
111 echo "$result"
112 echo "yum return code: $return_code"
113
114 if [[ "$pacemaker_status" == "active" ]] ; then
115     echo "Starting cluster node"
116     pcs cluster start
117
118     hostname=$(hostname -s)
119     tstart=$(date +%s)
120     while [[ "$(pcs status | grep "^Online" | grep -F -o $hostname)" == "" ]]; do
121         sleep 5
122         tnow=$(date +%s)
123         if (( tnow-tstart > cluster_start_timeout )) ; then
124             echo "ERROR $hostname failed to join cluster in $cluster_start_timeout seconds"
125             pcs status
126             exit 1
127         fi
128     done
129
130     RETVAL=$( pcs resource show galera-master | grep wsrep_cluster_address | grep -q `crm_node -n` ; echo $? )
131
132     if [[ $RETVAL -eq 0 && -e /etc/sysconfig/clustercheck ]]; then
133         tstart=$(date +%s)
134         while ! clustercheck; do
135             sleep 5
136             tnow=$(date +%s)
137             if (( tnow-tstart > galera_sync_timeout )) ; then
138                 echo "ERROR galera sync timed out"
139                 exit 1
140             fi
141         done
142     fi
143
144     echo "Waiting for pacemaker cluster to settle"
145     if ! timeout -k 10 $cluster_settle_timeout crm_resource --wait; then
146         echo "ERROR timed out while waiting for the cluster to settle"
147         exit 1
148     fi
149
150     pcs status
151 fi
152
153
154 echo "Finished yum_update.sh on server $deploy_server_id at `date` with return code: $return_code"
155
156 exit $return_code