2007-09-26 19:20:47 +00:00
|
|
|
#!/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).
|
2004-09-09 04:10:47 +00:00
|
|
|
#
|
|
|
|
# chkconfig: - 65 35
|
2007-09-26 19:20:47 +00:00
|
|
|
# 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
|
2004-09-09 04:10:47 +00:00
|
|
|
|
2007-04-26 19:01:43 +00:00
|
|
|
. /etc/init.d/functions
|
2004-09-09 04:10:47 +00:00
|
|
|
|
2007-04-26 19:01:43 +00:00
|
|
|
RETVAL=0
|
2007-09-26 19:20:47 +00:00
|
|
|
|
2007-04-26 19:01:43 +00:00
|
|
|
prog=dhcpd
|
|
|
|
dhcpd=/usr/sbin/dhcpd
|
|
|
|
lockfile=/var/lock/subsys/dhcpd
|
2007-09-26 19:20:47 +00:00
|
|
|
pidfile=/var/run/dhcpd.pid
|
2004-09-09 04:10:47 +00:00
|
|
|
|
2007-09-26 19:20:47 +00:00
|
|
|
[ -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
|
2007-10-08 17:58:17 +00:00
|
|
|
if [ "$found" = 1 ]; then
|
2007-09-26 19:20:47 +00:00
|
|
|
[ -f "$arg" ] && echo "$arg"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [ "$arg" = "-cf" ]; then
|
|
|
|
found=1
|
|
|
|
continue
|
2007-04-26 19:01:43 +00:00
|
|
|
fi
|
|
|
|
done
|
2007-09-26 19:20:47 +00:00
|
|
|
echo "/etc/dhcpd.conf"
|
2005-11-15 17:11:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 19:20:47 +00:00
|
|
|
conf="$(findConfig "$DHCPDARGS")"
|
2007-04-26 19:01:43 +00:00
|
|
|
|
2005-11-15 17:11:05 +00:00
|
|
|
if [ ! -f /var/lib/dhcpd/dhcpd.leases ] ; then
|
2007-04-26 19:01:43 +00:00
|
|
|
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
|
2004-09-22 14:55:33 +00:00
|
|
|
fi
|
2005-11-15 17:11:05 +00:00
|
|
|
|
2007-04-26 19:01:43 +00:00
|
|
|
configtest() {
|
|
|
|
[ -x $dhcpd ] || return 5
|
2007-09-26 19:20:47 +00:00
|
|
|
[ -f $conf ] || return 6
|
|
|
|
$dhcpd -q -t -cf $conf
|
2007-04-26 19:01:43 +00:00
|
|
|
RETVAL=$?
|
|
|
|
return $RETVAL
|
2004-09-09 04:15:43 +00:00
|
|
|
}
|
|
|
|
|
2004-09-09 04:10:47 +00:00
|
|
|
start() {
|
2007-04-26 19:01:43 +00:00
|
|
|
[ -x $dhcpd ] || return 5
|
2007-09-26 19:20:47 +00:00
|
|
|
[ -f $conf ] || return 6
|
|
|
|
|
|
|
|
pidofproc $prog >/dev/null 2>&1
|
|
|
|
RETVAL=$?
|
|
|
|
[ $RETVAL -eq 0 ] && return $RETVAL
|
|
|
|
|
2007-04-26 19:01:43 +00:00
|
|
|
echo -n $"Starting $prog: "
|
|
|
|
daemon $dhcpd $DHCPDARGS 2>/dev/null
|
|
|
|
RETVAL=$?
|
2007-06-20 17:25:50 +00:00
|
|
|
echo
|
2007-04-26 19:01:43 +00:00
|
|
|
[ $RETVAL = 0 ] && touch $lockfile
|
|
|
|
return $RETVAL
|
2004-09-09 04:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2007-09-26 19:20:47 +00:00
|
|
|
pidofproc $prog >/dev/null 2>&1
|
2007-10-08 17:58:17 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2007-09-26 19:20:47 +00:00
|
|
|
RETVAL=7
|
|
|
|
return $RETVAL
|
|
|
|
fi
|
|
|
|
|
2007-04-26 19:01:43 +00:00
|
|
|
echo -n $"Shutting down $prog: "
|
2007-07-10 18:59:53 +00:00
|
|
|
killproc $prog
|
2007-04-26 19:01:43 +00:00
|
|
|
RETVAL=$?
|
2007-09-26 19:20:47 +00:00
|
|
|
|
|
|
|
[ $RETVAL = 0 ] && success || failure
|
2007-06-20 17:25:50 +00:00
|
|
|
echo
|
2007-04-26 19:01:43 +00:00
|
|
|
[ $RETVAL = 0 ] && rm -f $lockfile
|
|
|
|
return $RETVAL
|
2004-09-09 04:10:47 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 19:20:47 +00:00
|
|
|
if [ ! -x $dhcdbd ]; then
|
|
|
|
RETVAL=5
|
|
|
|
exit $RETVAL
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
RETVAL=2
|
|
|
|
exit $RETVAL
|
|
|
|
fi
|
|
|
|
|
2004-09-09 04:10:47 +00:00
|
|
|
case "$1" in
|
2007-04-26 19:01:43 +00:00
|
|
|
start)
|
|
|
|
start
|
2007-09-26 19:20:47 +00:00
|
|
|
RETVAL=$?
|
2007-04-26 19:01:43 +00:00
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
2007-09-26 19:20:47 +00:00
|
|
|
RETVAL=$?
|
2007-04-26 19:01:43 +00:00
|
|
|
;;
|
2007-09-26 19:20:47 +00:00
|
|
|
restart|force-reload)
|
|
|
|
stop && start
|
|
|
|
RETVAL=$?
|
2007-04-26 19:01:43 +00:00
|
|
|
;;
|
2007-09-26 19:20:47 +00:00
|
|
|
try-restart|reload)
|
|
|
|
RETVAL=3
|
2007-04-26 19:01:43 +00:00
|
|
|
;;
|
|
|
|
condrestart)
|
|
|
|
if [ -f $lockfile ]; then
|
2007-09-26 19:20:47 +00:00
|
|
|
stop && start
|
|
|
|
RETVAL=$?
|
2007-04-26 19:01:43 +00:00
|
|
|
fi
|
|
|
|
;;
|
2007-09-26 19:20:47 +00:00
|
|
|
configtest)
|
2007-04-26 19:01:43 +00:00
|
|
|
configtest
|
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
status)
|
2007-09-26 19:20:47 +00:00
|
|
|
status $dhcpd
|
2007-04-26 19:01:43 +00:00
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo $"Usage: $0 {start|stop|restart|condrestart|configtest|status}"
|
|
|
|
RETVAL=3
|
|
|
|
;;
|
2004-09-09 04:10:47 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|