Merge "Implement Advanced Firewalling support"
[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=360
27
28 timestamp_file="$timestamp_dir/$update_identifier"
29 if [[ -a "$timestamp_file" ]]; then
30     echo "Not running for already-run timestamp \"$update_identifier\""
31     exit 0
32 fi
33 touch "$timestamp_file"
34
35 command_arguments=${command_arguments:-}
36
37 list_updates=$(yum list updates)
38
39 if [[ "$list_updates" == "" ]]; then
40     echo "No packages require updating"
41     exit 0
42 fi
43
44 pacemaker_status=$(systemctl is-active pacemaker)
45 pacemaker_dumpfile=$(mktemp)
46
47 if [[ "$pacemaker_status" == "active" ]] ; then
48     echo "Dumping Pacemaker config"
49     pcs cluster cib $pacemaker_dumpfile
50
51     echo "Checking for missing constraints"
52
53     if ! pcs constraint order show | grep "start openstack-nova-novncproxy-clone then start openstack-nova-api-clone"; then
54         pcs -f $pacemaker_dumpfile constraint order start openstack-nova-novncproxy-clone then openstack-nova-api-clone
55     fi
56
57     if ! pcs constraint order show | grep "start rabbitmq-clone then start openstack-keystone-clone"; then
58         pcs -f $pacemaker_dumpfile constraint order start rabbitmq-clone then openstack-keystone-clone
59     fi
60
61     if ! pcs constraint order show | grep "promote galera-master then start openstack-keystone-clone"; then
62         pcs -f $pacemaker_dumpfile constraint order promote galera-master then openstack-keystone-clone
63     fi
64
65     if ! pcs constraint order show | grep "start haproxy-clone then start openstack-keystone-clone"; then
66         pcs -f $pacemaker_dumpfile constraint order start haproxy-clone then openstack-keystone-clone
67     fi
68
69     if ! pcs constraint order show | grep "start memcached-clone then start openstack-keystone-clone"; then
70         pcs -f $pacemaker_dumpfile constraint order start memcached-clone then openstack-keystone-clone
71     fi
72
73     if ! pcs constraint order show | grep "promote redis-master then start openstack-ceilometer-central-clone"; then
74         pcs -f $pacemaker_dumpfile constraint order promote redis-master then start openstack-ceilometer-central-clone require-all=false
75     fi
76
77     if ! pcs resource defaults | grep "resource-stickiness: INFINITY"; then
78         pcs -f $pacemaker_dumpfile resource defaults resource-stickiness=INFINITY
79     fi
80
81     echo "Setting resource start/stop timeouts"
82     SERVICES="
83 haproxy
84 memcached
85 httpd
86 neutron-dhcp-agent
87 neutron-l3-agent
88 neutron-metadata-agent
89 neutron-openvswitch-agent
90 neutron-server
91 openstack-ceilometer-alarm-evaluator
92 openstack-ceilometer-alarm-notifier
93 openstack-ceilometer-api
94 openstack-ceilometer-central
95 openstack-ceilometer-collector
96 openstack-ceilometer-notification
97 openstack-cinder-api
98 openstack-cinder-scheduler
99 openstack-cinder-volume
100 openstack-glance-api
101 openstack-glance-registry
102 openstack-heat-api
103 openstack-heat-api-cfn
104 openstack-heat-api-cloudwatch
105 openstack-heat-engine
106 openstack-keystone
107 openstack-nova-api
108 openstack-nova-conductor
109 openstack-nova-consoleauth
110 openstack-nova-novncproxy
111 openstack-nova-scheduler"
112     for service in $SERVICES; do
113         pcs -f $pacemaker_dumpfile resource update $service op start timeout=100s op stop timeout=100s
114     done
115     # mongod start timeout is higher, setting only stop timeout
116     pcs resource update mongod op stop timeout=100s
117
118     echo "Applying new Pacemaker config"
119     pcs cluster cib-push $pacemaker_dumpfile
120
121     echo "Pacemaker running, stopping cluster node and doing full package update"
122     node_count=$(pcs status xml | grep -o "<nodes_configured.*/>" | grep -o 'number="[0-9]*"' | grep -o "[0-9]*")
123     if [[ "$node_count" == "1" ]] ; then
124         echo "Active node count is 1, stopping node with --force"
125         pcs cluster stop --force
126     else
127         pcs cluster stop
128     fi
129 else
130     echo "Excluding upgrading packages that are handled by config management tooling"
131     command_arguments="$command_arguments --skip-broken"
132     for exclude in $(cat /var/lib/tripleo/installed-packages/* | sort -u); do
133         command_arguments="$command_arguments --exclude $exclude"
134     done
135 fi
136
137 command=${command:-update}
138 full_command="yum -y $command $command_arguments"
139 echo "Running: $full_command"
140
141 result=$($full_command)
142 return_code=$?
143 echo "$result"
144 echo "yum return code: $return_code"
145
146 if [[ "$pacemaker_status" == "active" ]] ; then
147     echo "Starting cluster node"
148     pcs cluster start
149
150     hostname=$(hostname -s)
151     tstart=$(date +%s)
152     while [[ "$(pcs status | grep "^Online" | grep -F -o $hostname)" == "" ]]; do
153         sleep 5
154         tnow=$(date +%s)
155         if (( tnow-tstart > cluster_start_timeout )) ; then
156             echo "ERROR $hostname failed to join cluster in $cluster_start_timeout seconds"
157             pcs status
158             exit 1
159         fi
160     done
161
162     tstart=$(date +%s)
163     while ! clustercheck; do
164         sleep 5
165         tnow=$(date +%s)
166         if (( tnow-tstart > galera_sync_timeout )) ; then
167             echo "ERROR galera sync timed out"
168             exit 1
169         fi
170     done
171
172     pcs status
173
174 else
175     echo -n "true" > $heat_outputs_path.update_managed_packages
176 fi
177
178 echo "Finished yum_update.sh on server $deploy_server_id at `date`"
179
180 exit $return_code