aboutsummaryrefslogtreecommitdiffstats
path: root/main/ucarp/ucarp.initd
diff options
context:
space:
mode:
Diffstat (limited to 'main/ucarp/ucarp.initd')
-rw-r--r--[-rwxr-xr-x]main/ucarp/ucarp.initd108
1 files changed, 50 insertions, 58 deletions
diff --git a/main/ucarp/ucarp.initd b/main/ucarp/ucarp.initd
index cc09ad05e1..d547474aed 100755..100644
--- a/main/ucarp/ucarp.initd
+++ b/main/ucarp/ucarp.initd
@@ -1,67 +1,59 @@
#!/sbin/runscript
-# Copyright 1999-2008 Gentoo Foundation
+# Copyright 1999-2013 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"
- . /etc/conf.d/ucarp.$IFACE
-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" )
+# $Header: /var/cvsroot/gentoo-x86/net-misc/ucarp/files/ucarp.initd-r1,v 1.1 2013/03/25 10:32:03 dev-zero Exp $
+
+description="UCARP is a portable implementation of the CARP protocol"
+description_logstatus="Logs the status of ${SVCNAME} to syslog"
+description_demote="Demotes ${SVCNAME} from master to backup"
+
+extra_started_commands="logstatus demote"
+
+command="/usr/sbin/ucarp"
+command_args="--interface=${UCARP_INTERFACE} \
+ --srcip=${UCARP_SOURCEADDRESS} \
+ --vhid=${UCARP_VHID} \
+ --passfile=${UCARP_PASSFILE} \
+ --addr=${UCARP_VIRTUALADDRESS} \
+ --upscript=${UCARP_UPSCRIPT} \
+ --downscript=${UCARP_DOWNSCRIPT} \
+ --xparam=${UCARP_VIRTUALPREFIX} \
+ ${UCARP_OPTS}"
+
+pidfile="/var/run/${SVCNAME}.pid"
+command_background="yes"
+
+required_files="${UCARP_PASSFILE} ${UCARP_UPSCRIPT} ${UCARP_DOWNSCRIPT}"
+
+depend() {
+ need net
+ use logger
+ provide ucarp
}
-if [ -z "$REALIP" ]; then
- REALIP=$( get_first_ip $IFACE )
-fi
-
-depend () {
- need net
- after firewall
-}
-
-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 \
- -u $UP -d $DOWN $EXTRA_ARGS -z
- eend $?
+start_pre() {
+ local required_vars='UCARP_INTERFACE UCARP_SOURCEADDRESS UCARP_VHID
+ UCARP_PASSFILE UCARP_VIRTUALADDRESS UCARP_UPSCRIPT
+ UCARP_DOWNSCRIPT UCARP_VIRTUALPREFIX'
+
+ local config_var=''
+ for config_var in $required_vars; do
+ if test -z "$(eval echo \$$config_var)"; then
+ eerror "Missing or empty config variable '$config_var'"
+ ewarn "You have to edit /etc/conf.d/${SVCNAME} first"
+ return 1
+ fi
+ done
}
-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
+logstatus() {
+ ebegin "Logging status of ${SVCNAME} to syslog"
+ start-stop-daemon --signal SIGUSR1 --pidfile "${pidfile}"
+ eend $?
}
-stop () {
- ebegin "Shutting down ucarp $IFACE"
- start-stop-daemon --stop --exec $DAEMON \
- -p /var/run/ucarp-$IFACE.pid
- eend $?
+demote() {
+ ebegin "Demote ${SVCNAME} from master to backup"
+ start-stop-daemon --signal SIGUSR2 --pidfile "${pidfile}"
+ eend $?
}
-