diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..48b8c83 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +NAME = carp_faillover +DESTDIR ?= /usr/local +prefix ?= ${DESTDIR}/usr/local +exec_prefix ?= ${prefix} +bindir ?= ${exec_prefix}/bin +sysconfdir ?= ${prefix}/etc/${NAME} +datarootdir ?= ${prefix}/share +datadir ?= ${datarootdir}/${NAME} + +install: + install -D ${datadir} + install carp_failover.conf ${datadir} + install carp_failover ${exec_prefix} + +.PHONY: install diff --git a/carp_failover b/carp_failover new file mode 100644 index 0000000..53f2642 --- /dev/null +++ b/carp_failover @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +to_backup() { + # NOOP +} + +to_master() { + # NOOP +} + +if [ ! -f "$1" ]; then + echo "Config file does not exist" + exit 1 +fi + +source "$1" +if [ "$?" -gt "0" ]; then + echo "loading config file caused an error" + exit 1 +fi + +old_state="" +while true; do + state="$(ifconfig | awk '/carp/ { print $2 }')" + if [ "$old_state" = "${state}" ]; then + sleep 10 + continue + fi + if [ "$state" = "BACKUP" ]; then + logger "going into backup mode" + to_backup + elif [ "$state" = "MASTER" ]; then + logger "going into master mode" + to_master + else + logger "unknown state '${state}'!" + fi + old_state="$state" + sleep 10 +done diff --git a/carp_failover.conf b/carp_failover.conf new file mode 100644 index 0000000..b6917f6 --- /dev/null +++ b/carp_failover.conf @@ -0,0 +1,9 @@ +# Set the action when the node changes to BACKUP state. +to_backup() { + logger "changed to backup" +} + +# Set the action when the node changes to MASTER state. +to_master() { + logger "changed to master" +}