Skip to content

Instantly share code, notes, and snippets.

@sreimers
Created February 19, 2016 06:45
Show Gist options
  • Save sreimers/c5ed3e1381d3d34bc5d9 to your computer and use it in GitHub Desktop.
Save sreimers/c5ed3e1381d3d34bc5d9 to your computer and use it in GitHub Desktop.
Hetzner simple Failover Script
#!/bin/bash
#------------------------------------------------------------
# title :failover.sh
# description :This script will call hetzner failover api
# author :Sebastian Reimers <[email protected]>
# date :18.02.2016
# version :0.1
#------------------------------------------------------------
# settings
hlogin=""
hpassword=""
hserver="https://robot-ws.your-server.de/failover"
failoverip=""
#------------------------------------------------------------
lhost=$(cat /tmp/failover_last)
chost=$(curl http://10.10.1.1/host.html 2>/dev/null)
if [ "$lhost" != "$chost" ]; then
echo "$lhost != $chost"
curl -u $hlogin:$hpassword $hserver/$failoverip -d active_server_ip=$chost
echo $chost > /tmp/failover_last
fi
@lbenedix
Copy link

lbenedix commented Oct 11, 2016

I would suggest getting the variable lhost from hetzner:

lhost=$(curl -s -u $hlogin:$hpassword $hserver/$failoverip | jq -r '.failover.active_server_ip')

This would work on a freshly booted machine where nothing is in /tmp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment