initial commit

This commit is contained in:
Gibheer 2020-03-02 15:31:56 +01:00
parent 4d82e50db8
commit 0d28f8880c
3 changed files with 64 additions and 0 deletions

15
Makefile Normal file
View File

@ -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

40
carp_failover Normal file
View File

@ -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

9
carp_failover.conf Normal file
View File

@ -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"
}