Merge "Setting keystone region for tacker"
[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 command_arguments=${command_arguments:-}
42
43 list_updates=$(yum list updates)
44
45 if [[ "$list_updates" == "" ]]; then
46     echo "No packages require updating"
47     exit 0
48 fi
49
50 pacemaker_status=""
51 if hiera -c /etc/puppet/hiera.yaml service_names | grep -q pacemaker; then
52     pacemaker_status=$(systemctl is-active pacemaker)
53 fi
54
55 # Fix the redis/rabbit resource start/stop timeouts. See https://bugs.launchpad.net/tripleo/+bug/1633455
56 # and https://bugs.launchpad.net/tripleo/+bug/1634851
57 if [[ "$pacemaker_status" == "active" && \
58       "$(hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid)" = "$(facter hostname)" ]] ; then
59     if pcs resource show rabbitmq | grep -E "start.*timeout=100"; then
60         pcs resource update rabbitmq op start timeout=200s
61     fi
62     if pcs resource show rabbitmq | grep -E "stop.*timeout=90"; then
63         pcs resource update rabbitmq op stop timeout=200s
64     fi
65     if pcs resource show redis | grep -E "start.*timeout=120"; then
66         pcs resource update redis op start timeout=200s
67     fi
68     if pcs resource show redis | grep -E "stop.*timeout=120"; then
69         pcs resource update redis op stop timeout=200s
70     fi
71 fi
72
73 # special case https://bugs.launchpad.net/tripleo/+bug/1635205 +bug/1669714
74 special_case_ovs_upgrade_if_needed
75
76 if [[ "$pacemaker_status" == "active" ]] ; then
77     echo "Pacemaker running, stopping cluster node and doing full package update"
78     node_count=$(pcs status xml | grep -o "<nodes_configured.*/>" | grep -o 'number="[0-9]*"' | grep -o "[0-9]*")
79     if [[ "$node_count" == "1" ]] ; then
80         echo "Active node count is 1, stopping node with --force"
81         pcs cluster stop --force
82     else
83         pcs cluster stop
84     fi
85 else
86     echo "Upgrading openstack-puppet-modules and its dependencies"
87     yum -q -y update openstack-puppet-modules
88     yum deplist openstack-puppet-modules | awk '/dependency/{print $2}' | xargs yum -q -y update
89     echo "Upgrading other packages is handled by config management tooling"
90     echo -n "true" > $heat_outputs_path.update_managed_packages
91     exit 0
92 fi
93
94 command=${command:-update}
95 full_command="yum -q -y $command $command_arguments"
96 echo "Running: $full_command"
97
98 result=$($full_command)
99 return_code=$?
100 echo "$result"
101 echo "yum return code: $return_code"
102
103 if [[ "$pacemaker_status" == "active" ]] ; then
104     echo "Starting cluster node"
105     pcs cluster start
106
107     hostname=$(hostname -s)
108     tstart=$(date +%s)
109     while [[ "$(pcs status | grep "^Online" | grep -F -o $hostname)" == "" ]]; do
110         sleep 5
111         tnow=$(date +%s)
112         if (( tnow-tstart > cluster_start_timeout )) ; then
113             echo "ERROR $hostname failed to join cluster in $cluster_start_timeout seconds"
114             pcs status
115             exit 1
116         fi
117     done
118
119     RETVAL=$( pcs resource show galera-master | grep wsrep_cluster_address | grep -q `crm_node -n` ; echo $? )
120
121     if [[ $RETVAL -eq 0 && -e /etc/sysconfig/clustercheck ]]; then
122         tstart=$(date +%s)
123         while ! clustercheck; do
124             sleep 5
125             tnow=$(date +%s)
126             if (( tnow-tstart > galera_sync_timeout )) ; then
127                 echo "ERROR galera sync timed out"
128                 exit 1
129             fi
130         done
131     fi
132
133     echo "Waiting for pacemaker cluster to settle"
134     if ! timeout -k 10 $cluster_settle_timeout crm_resource --wait; then
135         echo "ERROR timed out while waiting for the cluster to settle"
136         exit 1
137     fi
138
139     pcs status
140 fi
141
142 echo "Finished yum_update.sh on server $deploy_server_id at `date`"
143
144 exit $return_code