dhcp/dhcpd.init
2005-11-15 17:11:05 +00:00

129 lines
2.2 KiB
Bash

#!/bin/sh
#
# dhcpd This shell script takes care of starting and stopping
# dhcpd.
#
# chkconfig: - 65 35
# description: dhcpd provide access to Dynamic Host Control Protocol.
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
. /etc/sysconfig/dhcpd
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/dhcpd ] || exit 0
cfOption()
{ let i=0;
for a in $*;
do ((++i));
if [ $a = -cf ]; then
((++i));
eval 'echo $'$i;
elif [[ $a = -cf* ]]; then
echo ${a#-cf};
fi;
done;
}
CF=`cfOption $DHCPDARGS`
if [ -z "$CF" ]; then
CF='/etc/dhcpd.conf';
fi
[ -f "$CF" ] || exit 0
if [ ! -f /var/lib/dhcpd/dhcpd.leases ] ; then
mkdir -p /var/lib/dhcpd
touch /var/lib/dhcpd/dhcpd.leases
[ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon /var/lib/dhcp/dhcpd.leases >/dev/null 2>&1
fi
RETVAL=0
prog="dhcpd"
configtest()
{
/usr/sbin/dhcpd -q -t -cf $CF
return $?
}
start() {
# Start daemons.
echo -n $"Starting $prog: "
daemon /usr/sbin/dhcpd ${DHCPDARGS} 2>/dev/null
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
touch /var/lock/subsys/dhcpd
if [ -x /usr/bin/logger ]; then
/usr/bin/logger -t dhcpd 'dhcpd startup succeeded'
fi;
else
if [ -x /usr/bin/logger ]; then
/usr/bin/logger -t dhcpd 'dhcpd startup failed'
fi;
fi
return $RETVAL
}
stop() {
# Stop daemons.
echo -n $"Shutting down $prog: "
killproc dhcpd
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
rm -f /var/lock/subsys/dhcpd
if [ -x /usr/bin/logger ]; then
/usr/bin/logger -t dhcpd 'dhcpd shutdown succeeded'
fi;
else
if [ -x /usr/bin/logger ]; then
/usr/bin/logger -t dhcpd 'dhcpd shutdown failed'
fi;
fi
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
configtest || exit $?
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/dhcpd ]; then
stop
start
RETVAL=$?
fi
;;
configtest|check|testconfig|test)
configtest
RETVAL=$?
;;
status)
status dhcpd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|configtest|status}"
exit 1
esac
exit $RETVAL