keepalived: Add to_backup.sh script

This commit is contained in:
eiabea 2023-10-19 08:58:55 +02:00
parent 4170c4126d
commit 949c4329e2

View file

@ -161,7 +161,8 @@ CURL_CHECK='
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'
REROUTE_RESULT=$(curl -s -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d "$CURL_REROUTE" -X POST https://www.servercontrolpanel.de:443/WSEndUser?xsd=1)
# Do not trigger re-route before checking if the current may even has the correct IP
# REROUTE_RESULT=$(curl -s -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d "$CURL_REROUTE" -X POST https://www.servercontrolpanel.de:443/WSEndUser?xsd=1)
CHECK_RESULT=$(curl -s -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d "$CURL_CHECK" -X POST https://www.servercontrolpanel.de:443/WSEndUser?xsd=1)
FAILOVER_IP_ACTIVE=$(echo $CHECK_RESULT | grep YOUR_FAILOVER_IP | wc -l)
@ -186,6 +187,19 @@ Hints:
- _YOUR_VSERVER_NAME_ can be found in your SCP in the _General_ section of the corresponding server.
- _YOUR_VSERVER_MAC_ can also be found in your SCP in the _General_ section of the corresponding server (note that you need the MAC of your primary interface not the MAC of the vLAN).
**to_backup.sh**
```
#!/usr/bin/bash
# Ensure no to_master script is still running even though we got into backup state
if pgrep to_master.sh; then killall to_master.sh; fi
```
The above script kills the `to_master.sh` script if it is already running on this host. This prevents a race condition where 2 servers might want the vIP routed to themselves
# Step 3 - Set up Keepalived
## Step 3.1 - Install Keepalived
@ -229,6 +243,8 @@ vrrp_instance VI_1 {
10.132.0.100
}
notify_master /PATH/TO/YOUR/SCRIPT/to_master.sh
notify_backup /PATH/TO/YOUR/SCRIPT/to_backup.sh
notify_fault /PATH/TO/YOUR/SCRIPT/to_backup.sh
}
```
@ -249,6 +265,8 @@ vrrp_instance VI_1 {
10.132.0.100
}
notify_master /PATH/TO/YOUR/SCRIPT/to_master.sh
notify_backup /PATH/TO/YOUR/SCRIPT/to_backup.sh
notify_fault /PATH/TO/YOUR/SCRIPT/to_backup.sh
}
```