dhcp/dhcpd.init

151 lines
2.9 KiB
Plaintext
Raw Normal View History

2008-01-11 00:19:03 +00:00
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: dhcpd
# Default-Start:
# Default-Stop:
# 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/dhcp/dhcpd.conf
2008-01-11 00:19:03 +00:00
# config: /var/lib/dhcpd/dhcpd.leases
# pidfile: /var/run/dhcpd.pid
. /etc/rc.d/init.d/functions
2008-01-11 00:19:03 +00:00
RETVAL=0
prog=dhcpd
exec=/usr/sbin/dhcpd
2008-01-11 00:19:03 +00:00
lockfile=/var/lock/subsys/dhcpd
pidfile=/var/run/dhcpd.pid
statedir=/var/lib/dhcpd
[ -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/dhcp/dhcpd.conf"
2008-01-11 00:19:03 +00:00
}
config="$(findConfig "$DHCPDARGS")"
2008-01-11 00:19:03 +00:00
if [ ! -f $statedir/dhcpd.leases ] ; then
mkdir -p $statedir
touch $statedir/dhcpd.leases
[ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon $statedir/dhcpd.leases >/dev/null 2>&1
fi
configtest() {
[ -x $exec ] || return 5
[ -f $config ] || return 6
$exec -q -t -cf $config
2008-01-11 00:19:03 +00:00
RETVAL=$?
if [ $RETVAL -eq 1 ]; then
$exec -t -cf $config
else
echo "Syntax: OK" >&2
fi
2008-01-11 00:19:03 +00:00
return $RETVAL
}
rh_status() {
status -p $pidfile -l $(basename $lockfile) $exec
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
2008-01-11 00:19:03 +00:00
start() {
[ `id -u` -eq 0 ] || return 4
[ -x $exec ] || return 5
[ -f $config ] || return 6
2008-01-11 00:19:03 +00:00
rh_status_q && return 0
2008-01-11 00:19:03 +00:00
echo -n $"Starting $prog: "
daemon --pidfile=$pidfile $exec $DHCPDARGS 2>/dev/null
2008-01-11 00:19:03 +00:00
RETVAL=$?
2008-01-11 00:19:03 +00:00
echo
[ $RETVAL -eq 0 ] && touch $lockfile
2008-01-11 00:19:03 +00:00
return $RETVAL
}
stop() {
[ `id -u` -eq 0 ] || return 4
rh_status_q || return 0
2008-01-11 00:19:03 +00:00
echo -n $"Shutting down $prog: "
killproc -p $pidfile $prog
2008-01-11 00:19:03 +00:00
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
2008-01-11 00:19:03 +00:00
return $RETVAL
}
usage() {
echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
}
2008-01-11 00:19:03 +00:00
if [ $# -gt 1 ]; then
exit 2
2008-01-11 00:19:03 +00:00
fi
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload)
stop ; start
;;
condrestart|try-restart)
rh_status_q || exit 0
stop ; start
2008-01-11 00:19:03 +00:00
;;
reload)
usage
# unimplemented feature
exit 3
;;
2008-01-11 00:19:03 +00:00
configtest)
configtest
;;
status)
rh_status
2008-01-11 00:19:03 +00:00
;;
*)
usage
exit 2
2008-01-11 00:19:03 +00:00
;;
esac
exit $?