openslp/slpd.init

257 lines
6.8 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# slpd Start/Stop the OpenSLP SA daemon (slpd).
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# -Modified for RHS Linux by Damien Neil
# -Modified for COL by Raymund Will, <ray@lst.de>
# -Modified for OpenSLP by Matt Peterson <mpeterson@calderasystems.com>
# -Modified to be distribution agnostic by Bart Whiteley <bart@caldera.com>
# -Modified to be MORE agnostic by Erik Ratcliffe <eratcliffe@volutiontech.com>
# Red Hat "chkconfig" init header:
#
# chkconfig: 345 13 87
# description: slpd - OpenSLP daemon for the Service Location Protocol
# processname: slpd
# LSB init header:
#
### BEGIN INIT INFO
# Provides: openslp slpd
# Required-Start: $named
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Description: slpd - OpenSLP daemon for the Service Location Protocol
### END INIT INFO
#///////////// multicast_route_set() //////////////#
# #
# Does nothing if a route exists that supports #
# multicast traffic. If no routes supporting #
# multicast traffic exists, the function tries to #
# add one. A 0 is returned on success and a 1 #
# on failure. One parameter must be passed in. #
# This variable determins verbosity. If parameter #
# is non-zero debugging will appear #
# #
#//////////////////////////////////////////////////#
multicast_route_set()
{
PING_OPTIONS_1='-c1 -w1'
PING_OPTIONS_2='-c1 -i1'
MULTICAST_ADDRESS='239.255.255.253'
TMP_FILE=/tmp/route.check
PING_ERROR_NO_ROUTE='unreachable'
MSG_FAILED_TO_FIND='Failed to Detect Multicast Route'
MSG_SUCCESS_ON_FIND='Multicast Route Enabled'
MSG_ADDING_ROUTE='Attempting to Add Multicast Route ...'
MSG_FAILED_TO_ADD=' FAILED - Route NOT Added.'
MSG_SUCCES_ON_ADD=' SUCCESS - Route Added.'
CMD_GET_INTERFACE="netstat -i | awk 'BEGIN{}(NR>2)&&(!/^lo*/){print \$1}'"
CMD_ADD_ROUTE="route add -net 224.0.0.0 netmask 240.0.0.0"
ping $PING_OPTIONS_1 $MULTICAST_ADDRESS 2> $TMP_FILE 1> /dev/null
if [ $? = 2 ]; then
ping $PING_OPTIONS_2 $MULTICAST_ADDRESS 2> $TMP_FILE 1> /dev/null
fi
grep $PING_ERROR_NO_ROUTE $TMP_FILE > /dev/null 2>&1
err_unreachable_found=$?
#If errors, add route. Otherwise, do nothing
if [ -s $TMP_FILE ] && [ $err_unreachable_found = 0 ]; then
if [ $1 != 0 ]; then
echo $MSG_FAILED_TO_FIND
echo $MSG_ADDING_ROUTE
fi
$CMD_ADD_ROUTE `eval $CMD_GET_INTERFACE` > /dev/null 2>&1
retval=$?
if [ $1 != 0 ]; then
if [ $retval = 0 ]; then
echo $MSG_SUCCES_ON_ADD
else
echo $MSG_FAILED_TO_ADD
fi
fi
else
if [ $1 != 0 ]; then
echo -n $MSG_SUCCESS_ON_FIND
fi
retval=0
fi
rm -f $TMP_FILE # Clean up
return $retval
}
NAME=slpd
DAEMON=/usr/sbin/$NAME
# Change to root
OLDDIR=`pwd`
cd /
# Source function library or libraries. Start with the
# uncommon ones like /etc[/rc.d]/init.d/functions, and then
# source in the LSB functions if they exist (which will
# override functions that may be defined in the former
# functions library). Finally, if /etc/sysconfig/slpd
# exists (like on SCO Linux systems), source it in Just
# In Case(tm).
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
fi
if [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
fi
if [ -f /etc/sysconfig/$NAME ]; then
. /etc/sysconfig/$NAME
fi
# No executable daemon, no go...
test -x $DAEMON || exit 1
# Lock files seem to be very, very consistent across distros...
LOCK=/var/lock/subsys/$NAME
# Run/PID files seem to be consistent as well...
RUNPID=/var/run/$NAME
# Make RETVAL default to 0...
RETVAL=0
#
# See how we were called.
#
case "$1" in
start)
# Check if we're already running...
if [ ! "$LOCK" = "" ] && [ -f $LOCK ]; then
exit 0
fi
echo -n 'Starting slpd: '
# Attempt to guarantee a multicast route...
multicast_route_set 1
multicast_enabled=$?
if [ "$multicast_enabled" != "0" ] ; then
echo "Failure: No Route Available for Multicast Traffic"
exit 1
fi
# Try to start it up, beginning with LSB, then Red Hat,
# then OpenLinux. If there are other methods for starting
# daemons and they don't accidentally fall into one of those
# categories (look below before jumping to conclusions), let
# someone know so this can be fixed...
if [ -x /sbin/startproc ]; then
startproc $DAEMON $OPTIONS
RETVAL=$?
elif grep ^startproc\(\) /etc/rc.d/init.d/functions > /dev/null 2>&1 || \
grep ^startproc\(\) /etc/init.d/functions > /dev/null 2>&1; then
startproc $DAEMON $OPTIONS
RETVAL=$?
elif grep ^daemon\(\) /etc/rc.d/init.d/functions > /dev/null 2>&1 || \
grep ^daemon\(\) /etc/init.d/functions > /dev/null 2>&1; then
daemon $DAEMON
RETVAL=$?
else
if [ -x /sbin/ssd ]; then
ssd -S -n $NAME -x $DAEMON -- $OPTIONS
RETVAL=$?
fi
fi
if [ $RETVAL -eq 0 ]; then touch $LOCK; fi
echo
;;
stop)
# Are we even running? Check first...
if [ -f $LOCK ]; then
echo -n 'Stopping slpd: '
if [ -x /sbin/killproc ]; then
killproc $DAEMON
RETVAL=$?
elif grep killproc\(\) /etc/rc.d/init.d/functions > /dev/null 2>&1 || \
grep killproc\(\) /etc/init.d/functions > /dev/null 2>&1; then
killproc $DAEMON
RETVAL=$?
else
if [ -x /sbin/ssd ]; then
ssd -K -p /var/run/$NAME.pid -n $NAME
RETVAL=$?
fi
fi
if [ $RETVAL -eq 0 ]; then rm -f $LOCK; fi
else
echo "$NAME is not running"
RETVAL=0
fi
echo
;;
reload|restart)
cd $OLDDIR
$0 stop
$0 start
RETVAL=$?
cd /
;;
condrestart)
[ -f $LOCK ] && $0 restart || :
;;
status)
if [ -x /sbin/checkproc ]; then
/sbin/checkproc $NAME > /dev/null 2>&1
elif grep checkproc\(\) /etc/rc.d/init.d/functions > /dev/null 2>&1 || \
grep checkproc\(\) /etc/init.d/functions > /dev/null 2>&1; then
checkproc $NAME > /dev/null 2>&1
elif grep status\(\) /etc/rc.d/init.d/functions > /dev/null 2>&1 || \
grep status\(\) /etc/init.d/functions > /dev/null 2>&1; then
status $NAME > /dev/null 2>&1
else
pidof $NAME > /dev/null 2>&1
fi
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "$NAME is running."
else
echo "$NAME is not running."
fi
;;
*)
echo "Usage: slpd {start|stop|restart|condrestart|reload|status}"
exit 1
esac
exit $RETVAL