Add SSH timeout in escalation.sh.sample.
authorBo Peng <pengbo@sraoss.co.jp>
Fri, 6 Oct 2023 13:30:23 +0000 (22:30 +0900)
committerBo Peng <pengbo@sraoss.co.jp>
Fri, 6 Oct 2023 13:30:23 +0000 (22:30 +0900)
src/sample/scripts/escalation.sh.sample

index 5ae7e6f4b28ee9c49fc16da3372809d5bc18a16f..c590af846a99453280527fd08094ddf9b725812f 100755 (executable)
@@ -7,17 +7,20 @@ 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.137.150
 DEVICE=enp0s8
 
 for pgpool in "${PGPOOLS[@]}"; do
-    [ "$HOSTNAME" = "$pgpool" ] && continue
+    [ "$HOSTNAME" = "${pgpool}" ] && continue
 
-    ssh -T ${SSH_OPTIONS} ${POSTGRESQL_STARTUP_USER}@$pgpool "
-        /usr/bin/sudo /sbin/ip addr del $VIP/24 dev $DEVICE
+    timeout ${SSH_TIMEOUT} ssh -T ${SSH_OPTIONS} ${POSTGRESQL_STARTUP_USER}@${pgpool} "
+        /usr/bin/sudo /sbin/ip addr del ${VIP}/24 dev ${DEVICE}
     "
+    if [ $? -ne 0 ]; then
+        echo failed to release VIP on ${pgpool}.
+    fi
 done
 exit 0