blob: 01ee7fa1696ad45a4224a54dc34b97dca1b6f591 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/bin/bash
# This script is run by wd_escalation_command to bring down the virtual IP on other pgpool nodes
# before bringing up the virtual IP on the new active pgpool node.
set -o xtrace
POSTGRESQL_STARTUP_USER=postgres
SSH_KEY_FILE=id_rsa_pgpool
SSH_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/${SSH_KEY_FILE}"
SSH_TIMEOUT=5
PGPOOLS=(server1 server2 server3)
VIP=192.168.100.50
DEVICE=enp0s8
CIDR_NETMASK=24
for pgpool in "${PGPOOLS[@]}"; do
[ "$HOSTNAME" = "${pgpool}" ] && continue
timeout ${SSH_TIMEOUT} ssh -T ${SSH_OPTIONS} ${POSTGRESQL_STARTUP_USER}@${pgpool} "
/sbin/ip addr show dev ${DEVICE} | grep ${VIP} > /dev/null 2>&1
"
if [ $? -eq 0 ]; then
timeout ${SSH_TIMEOUT} ssh -T ${SSH_OPTIONS} ${POSTGRESQL_STARTUP_USER}@${pgpool} "
/usr/bin/sudo /sbin/ip addr del ${VIP}/${CIDR_NETMASK} dev ${DEVICE}
"
if [ $? -ne 0 ]; then
echo ERROR: escalation.sh: failed to release VIP on ${pgpool}.
fi
fi
done
exit 0
|