Merge "Add TimeZone parameter for all node types"
[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         timeout -k 10 $timeout crm_resource --wait
30         return
31       fi
32   done
33
34   echo "$service never $state after $timeout seconds" | tee /dev/fd/2
35   exit 1
36
37 }
38
39 # Run if pacemaker is running, we're the bootstrap node,
40 # and we're updating the deployment (not creating).
41 if [ "$pacemaker_status" = "active" -a \
42      "$(hiera bootstrap_nodeid)" = "$(facter hostname)" -a \
43      "$(hiera update_identifier)" != "nil" ]; then
44
45     #ensure neutron constraints like
46     #https://review.openstack.org/#/c/245093/
47     if  pcs constraint order show  | grep "start neutron-server-clone then start neutron-ovs-cleanup-clone"; then
48         pcs constraint remove order-neutron-server-clone-neutron-ovs-cleanup-clone-mandatory
49     fi
50
51     pcs resource disable httpd
52     check_resource httpd stopped 300
53     pcs resource disable openstack-keystone
54     check_resource openstack-keystone stopped 1800
55
56     if pcs status | grep haproxy-clone; then
57         pcs resource restart haproxy-clone
58     fi
59     pcs resource restart redis-master
60     pcs resource restart mongod-clone
61     pcs resource restart rabbitmq-clone
62     pcs resource restart memcached-clone
63     pcs resource restart galera-master
64
65     pcs resource enable openstack-keystone
66     check_resource openstack-keystone started 1800
67     pcs resource enable httpd
68     check_resource httpd started 800
69
70 fi