Merge "Allow dnsmasq_dns_servers to be configured for DHCP Agent"
[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 [[ -z "$update_identifier" ]]; then
14     echo "Not running due to unset update_identifier"
15     exit 0
16 fi
17
18 timestamp_dir=/var/lib/overcloud-yum-update
19 mkdir -p $timestamp_dir
20
21 # sanitise to remove unusual characters
22 update_identifier=${update_identifier//[^a-zA-Z0-9-_]/}
23
24 # seconds to wait for this node to rejoin the cluster after update
25 cluster_start_timeout=600
26 galera_sync_timeout=1800
27 cluster_settle_timeout=1800
28
29 timestamp_file="$timestamp_dir/$update_identifier"
30 if [[ -a "$timestamp_file" ]]; then
31     echo "Not running for already-run timestamp \"$update_identifier\""
32     exit 0
33 fi
34 touch "$timestamp_file"
35
36 command_arguments=${command_arguments:-}
37
38 list_updates=$(yum list updates)
39
40 if [[ "$list_updates" == "" ]]; then
41     echo "No packages require updating"
42     exit 0
43 fi
44
45 pacemaker_status=$(systemctl is-active pacemaker || :)
46
47 # Fix the redis/rabbit resource start/stop timeouts. See https://bugs.launchpad.net/tripleo/+bug/1633455
48 # and https://bugs.launchpad.net/tripleo/+bug/1634851
49 if [[ "$pacemaker_status" == "active" && \
50       "$(hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid)" = "$(facter hostname)" ]] ; then
51     if pcs resource show rabbitmq | grep -E "start.*timeout=100"; then
52         pcs resource update rabbitmq op start timeout=200s
53     fi
54     if pcs resource show rabbitmq | grep -E "stop.*timeout=90"; then
55         pcs resource update rabbitmq op stop timeout=200s
56     fi
57     if pcs resource show redis | grep -E "start.*timeout=120"; then
58         pcs resource update redis op start timeout=200s
59     fi
60     if pcs resource show redis | grep -E "stop.*timeout=120"; then
61         pcs resource update redis op stop timeout=200s
62     fi
63 fi
64
65 # Special-case OVS for https://bugs.launchpad.net/tripleo/+bug/1635205
66 special_case_ovs_upgrade_if_needed
67
68 if [[ "$pacemaker_status" == "active" ]] ; then
69     echo "Pacemaker running, stopping cluster node and doing full package update"
70     node_count=$(pcs status xml | grep -o "<nodes_configured.*/>" | grep -o 'number="[0-9]*"' | grep -o "[0-9]*")
71     if [[ "$node_count" == "1" ]] ; then
72         echo "Active node count is 1, stopping node with --force"
73         pcs cluster stop --force
74     else
75         pcs cluster stop
76     fi
77 else
78     echo "Upgrading openstack-puppet-modules and its dependencies"
79     yum -q -y update openstack-puppet-modules
80     yum deplist openstack-puppet-modules | awk '/dependency/{print $2}' | xargs yum -q -y update
81     echo "Upgrading other packages is handled by config management tooling"
82     echo -n "true" > $heat_outputs_path.update_managed_packages
83     exit 0
84 fi
85
86 command=${command:-update}
87 full_command="yum -q -y $command $command_arguments"
88 echo "Running: $full_command"
89
90 result=$($full_command)
91 return_code=$?
92 echo "$result"
93 echo "yum return code: $return_code"
94
95 # Writes any changes caused by alterations to os-net-config and bounces the
96 # interfaces *before* restarting the cluster.
97 os-net-config -c /etc/os-net-config/config.json -v --detailed-exit-codes
98 RETVAL=$?
99 if [[ $RETVAL == 2 ]]; then
100     echo "os-net-config: interface configuration files updated successfully"
101 elif [[ $RETVAL != 0 ]]; then
102     echo "ERROR: os-net-config configuration failed"
103     exit $RETVAL
104 fi
105
106 if [[ "$pacemaker_status" == "active" ]] ; then
107     echo "Starting cluster node"
108     pcs cluster start
109
110     hostname=$(hostname -s)
111     tstart=$(date +%s)
112     while [[ "$(pcs status | grep "^Online" | grep -F -o $hostname)" == "" ]]; do
113         sleep 5
114         tnow=$(date +%s)
115         if (( tnow-tstart > cluster_start_timeout )) ; then
116             echo "ERROR $hostname failed to join cluster in $cluster_start_timeout seconds"
117             pcs status
118             exit 1
119         fi
120     done
121
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
132     echo "Waiting for pacemaker cluster to settle"
133     if ! timeout -k 10 $cluster_settle_timeout crm_resource --wait; then
134         echo "ERROR timed out while waiting for the cluster to settle"
135         exit 1
136     fi
137
138     pcs status
139 fi
140
141 echo "Finished yum_update.sh on server $deploy_server_id at `date`"
142
143 exit $return_code