dhcp/dhcpd.init
2007-10-24 17:47:43 +00:00

147 lines
2.9 KiB
Bash

#!/bin/sh
#
### BEGIN INIT INFO
# Provides: dhcpd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start:
# Required-Start: $network
# Required-Stop:
# Short-Description: Start and stop the DHCP server
# Description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP)
# server.
### END INIT INFO
#
# The fields below are left around for legacy tools (will remove later).
#
# chkconfig: - 65 35
# description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP) \
# server
# processname: dhcpd
# config: /etc/dhcpd.conf
# config: /var/lib/dhcpd/dhcpd.leases
# pidfile: /var/run/dhcpd.pid
. /etc/init.d/functions
RETVAL=0
prog=dhcpd
dhcpd=/usr/sbin/dhcpd
lockfile=/var/lock/subsys/dhcpd
pidfile=/var/run/dhcpd.pid
[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
# if the user specified a different config file, make sure we reference it
findConfig() {
for arg in $DHCPDARGS ; do
if [ "$found" = 1 ]; then
[ -f "$arg" ] && echo "$arg"
return
fi
if [ "$arg" = "-cf" ]; then
found=1
continue
fi
done
echo "/etc/dhcpd.conf"
}
conf="$(findConfig "$DHCPDARGS")"
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/dhcpd/dhcpd.leases >/dev/null 2>&1
fi
configtest() {
[ -x $dhcpd ] || return 5
[ -f $conf ] || return 6
$dhcpd -q -t -cf $conf
RETVAL=$?
return $RETVAL
}
start() {
[ -x $dhcpd ] || return 5
[ -f $conf ] || return 6
pidofproc $prog >/dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && return $RETVAL
echo -n $"Starting $prog: "
daemon $dhcpd $DHCPDARGS 2>/dev/null
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
return $RETVAL
}
stop() {
pidofproc $prog >/dev/null 2>&1
if [ $? -ne 0 ]; then
RETVAL=7
return $RETVAL
fi
echo -n $"Shutting down $prog: "
killproc $prog
RETVAL=$?
[ $RETVAL = 0 ] && success || failure
echo
[ $RETVAL = 0 ] && rm -f $lockfile
return $RETVAL
}
if [ ! -x $dhcdbd ]; then
RETVAL=5
exit $RETVAL
fi
if [ $# -gt 1 ]; then
RETVAL=2
exit $RETVAL
fi
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart|force-reload)
stop ; start
RETVAL=$?
;;
try-restart|reload)
RETVAL=3
;;
condrestart)
if [ -f $lockfile ]; then
stop ; start
RETVAL=$?
fi
;;
configtest)
configtest
RETVAL=$?
;;
status)
status $dhcpd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|configtest|status}"
RETVAL=3
;;
esac
exit $RETVAL