Failover without Hetzner addresses: the HostHenker

Even though we have already presented quite a few scripts over the last couple of weeks to perform automatic failover at Hetzner using Heartbeat, we also want to provide failover for setups where we don’t use any failover addresses. For these types of setups, we have written a shell script, called HostHenker.

HostHenker is a small shell script, which uses nc(1) to determine whether a daemon is listening on a given host. Based on whether a daemon is running, it adds an entry to /etc/hosts for this host or a fallback host. Invocation of this utility is simple:

hosthenker 3306

In this setup, the script tries to connect to and writes an entry for to /etc/hosts. The actual command invoked by this script is nc -zw 15. The -z flag enables zero-I/O-mode, effectively closing the connection as soon as it has been established, while -w 15 sets a 15-second timeout, which is often good enough.

Right before installing the new /etc/hosts file, HostHenker checks whether the new file is different from the original one. If this is the case, it writes a string to stderr, which can be useful when configuring this script to run as a cronjob.

The files:

Tags: , , , ,

Leave a Reply

Kumina helps companies innovate with the power of open source software. As specialists in managed IT operations since 2007, our mission is simple: building and managing the perfectly tailored technical infrastructures that allow our clients to thrive.

With fully managed solutions, we help our customers unlock the full potential of the cloud and Kubernetes. Our team also supports organisations with IT consulting and Kubernetes training courses. Learn more about our services or get in touch, we would love to hear about your business and projects.