ucarp.initd 1.36 KB
Newer Older
Michael Mason's avatar
Michael Mason committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/sbin/runscript
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $


# A simple script to start and stop a ucarp instance
DAEMON=/usr/sbin/ucarp

IFACE="${SVCNAME#*.}"
if [ -n "$IFACE" ] && [ "${SVCNAME}" != "ucarp" ]; then
	UP="/etc/ucarp/vip-up-$IFACE.sh"
	DOWN="/etc/ucarp/vip-down-$IFACE.sh"
14
	. /etc/conf.d/ucarp.$IFACE
Michael Mason's avatar
Michael Mason committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
else
	UP="/etc/ucarp/vip-up.sh"
	DOWN="/etc/ucarp/vip-down.sh"
fi


# Get the primary ip address for a given interface
get_first_ip() {
	local foo=$( ip addr show $1 )
	[ $? != 0 ] && foo=""
	echo $( echo "$foo" | grep "inet " | head -n1 | \
		sed "s+^.*inet ++g; s+/.*$++g" )
}

if [ -z "$REALIP" ]; then
	REALIP=$( get_first_ip $IFACE )
fi

start () {
	ebegin "Starting ucarp $IFACE"
	start-stop-daemon --start --exec $DAEMON \
		--background -m -p /var/run/ucarp-$IFACE.pid -- \
		-i $IFACE -s $REALIP -v $VHID -p $PASSWORD -a $VIP \
38
		-u $UP -d $DOWN $EXTRA_ARGS -z 
Michael Mason's avatar
Michael Mason committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
	eend $?
}

status () {
	ebegin "ucarp $IFACE is ..."
	PIDS=$( pidof $( basename $DAEMON ))
	PID=$( cat /var/run/ucarp-$IFACE.pid 2>/dev/null )
	[ -n "$PID" ] && OK=$( echo "$PIDS" | grep "$PID" )
	if [ -n "$OK" ]; then
	echo "running" 
		exit 0
	else
		echo "not running"
		exit 1
	fi
}

stop () {
57
	ebegin "Shutting down ucarp $IFACE"
Michael Mason's avatar
Michael Mason committed
58 59 60 61
	start-stop-daemon --stop --exec $DAEMON \
		-p /var/run/ucarp-$IFACE.pid
	eend $?
}
62