Merge "Wire Neutron ML2 plugin and OVS agent settings as arrays"
[apex-tripleo-heat-templates.git] / extraconfig / tasks / pacemaker_resource_restart.sh
1 #!/bin/bash
2
3 set -eux
4
5 pacemaker_status=$(systemctl is-active pacemaker)
6 check_interval=3
7
8 function check_resource {
9
10   service=$1
11   state=$2
12   timeout=$3
13   tstart=$(date +%s)
14   tend=$(( $tstart + $timeout ))
15
16   if [ "$state" = "stopped" ]; then
17       match_for_incomplete='Started'
18   else # started
19       match_for_incomplete='Stopped'
20   fi
21
22   while (( $(date +%s) < $tend )); do
23       node_states=$(pcs status --full | grep "$service" | grep -v Clone)
24       if echo "$node_states" | grep -q "$match_for_incomplete"; then
25           echo "$service not yet $state, sleeping $check_interval seconds."
26           sleep $check_interval
27       else
28         echo "$service has $state"
29         return
30       fi
31   done
32
33   echo "$service never $state after $timeout seconds" | tee /dev/fd/2
34   exit 1
35
36 }
37
38 # Run if pacemaker is running, we're the bootstrap node,
39 # and we're updating the deployment (not creating).
40 if [ "$pacemaker_status" = "active" -a \
41      "$(hiera bootstrap_nodeid)" = "$(facter hostname)" -a \
42      "$(hiera update_identifier)" != "nil" ]; then
43
44     pcs resource disable httpd
45     check_resource httpd stopped 300
46     pcs resource disable openstack-keystone
47     check_resource openstack-keystone stopped 1200
48
49     if pcs status | grep haproxy-clone; then
50         pcs resource restart haproxy-clone
51     fi
52     pcs resource restart redis-master
53     pcs resource restart mongod-clone
54     pcs resource restart rabbitmq-clone
55     pcs resource restart memcached-clone
56     pcs resource restart galera-master
57
58     pcs resource enable openstack-keystone
59     check_resource openstack-keystone started 300
60     pcs resource enable httpd
61     check_resource httpd started 800
62
63 fi