db449ef
#!/bin/sh
db449ef
#
db449ef
### BEGIN INIT INFO
db449ef
# Provides: dhcpd
db449ef
# Default-Start:
db449ef
# Default-Stop:
db449ef
# Should-Start:
db449ef
# Required-Start: $network
db449ef
# Required-Stop:
db449ef
# Short-Description: Start and stop the DHCP server
db449ef
# Description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP)
db449ef
#              server.
db449ef
### END INIT INFO
db449ef
#
db449ef
# The fields below are left around for legacy tools (will remove later).
db449ef
#
db449ef
# chkconfig: - 65 35
db449ef
# description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP) \
db449ef
#              server
db449ef
# processname: dhcpd
31806bd
# config: /etc/dhcp/dhcpd.conf
db449ef
# config: /var/lib/dhcpd/dhcpd.leases
db449ef
# pidfile: /var/run/dhcpd.pid
db449ef
e648291
. /etc/rc.d/init.d/functions
db449ef
db449ef
RETVAL=0
db449ef
db449ef
prog=dhcpd
e648291
exec=/usr/sbin/dhcpd
db449ef
lockfile=/var/lock/subsys/dhcpd
db449ef
pidfile=/var/run/dhcpd.pid
db449ef
statedir=/var/lib/dhcpd
db449ef
db449ef
[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
db449ef
db449ef
# if the user specified a different config file, make sure we reference it
db449ef
findConfig() {
db449ef
    for arg in $DHCPDARGS ; do
db449ef
        if [ "$found" = 1 ]; then
db449ef
            [ -f "$arg" ] && echo "$arg"
db449ef
            return
db449ef
        fi
db449ef
        if [ "$arg" = "-cf" ]; then
db449ef
            found=1
db449ef
            continue
db449ef
        fi
db449ef
    done
4bf24c8
    echo "/etc/dhcp/dhcpd.conf"
db449ef
}
db449ef
e648291
config="$(findConfig "$DHCPDARGS")"
db449ef
db449ef
if [ ! -f $statedir/dhcpd.leases ] ; then
db449ef
    mkdir -p $statedir
db449ef
    touch $statedir/dhcpd.leases
db449ef
    [ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon $statedir/dhcpd.leases >/dev/null 2>&1
db449ef
fi
db449ef
db449ef
configtest() {
e648291
    [ -x $exec ] || return 5
e648291
    [ -f $config ] || return 6
e648291
    $exec -q -t -cf $config
db449ef
    RETVAL=$?
821e00d
    if [ $RETVAL -eq 1 ]; then
e648291
        $exec -t -cf $config
821e00d
    else
821e00d
        echo "Syntax: OK" >&2
821e00d
    fi
db449ef
    return $RETVAL
db449ef
}
db449ef
9c63bd9
rh_status() {
9c63bd9
    status -p $pidfile -l $(basename $lockfile) $exec
9c63bd9
}
9c63bd9
9c63bd9
rh_status_q() {
9c63bd9
    rh_status >/dev/null 2>&1
9c63bd9
}
9c63bd9
db449ef
start() {
e648291
    [ `id -u` -eq 0 ] || return 4
e648291
    [ -x $exec ] || return 5
e648291
    [ -f $config ] || return 6
db449ef
9c63bd9
    rh_status_q && return 0
db449ef
db449ef
    echo -n $"Starting $prog: "
9c63bd9
    daemon --pidfile=$pidfile $exec $DHCPDARGS 2>/dev/null
db449ef
    RETVAL=$?
9c63bd9
db449ef
    echo
e648291
    [ $RETVAL -eq 0 ] && touch $lockfile
db449ef
    return $RETVAL
db449ef
}
db449ef
db449ef
stop() {
e648291
    [ `id -u` -eq 0 ] || return 4
e648291
9c63bd9
    rh_status_q || return 0
9c63bd9
db449ef
    echo -n $"Shutting down $prog: "
9c63bd9
    killproc -p $pidfile $prog
db449ef
    RETVAL=$?
db449ef
db449ef
    echo
e648291
    [ $RETVAL -eq 0 ] && rm -f $lockfile
db449ef
    return $RETVAL
db449ef
}
db449ef
e648291
usage() {
e648291
    echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
e648291
}
e648291
db449ef
if [ $# -gt 1 ]; then
9c63bd9
    exit 2
db449ef
fi
db449ef
db449ef
case "$1" in
db449ef
    start)
db449ef
        start
db449ef
        ;;
db449ef
    stop)
db449ef
        stop
db449ef
        ;;
db449ef
    restart|force-reload)
db449ef
        stop ; start
db449ef
        ;;
e648291
    condrestart|try-restart)
9c63bd9
        rh_status_q || exit 0
9c63bd9
        stop ; start
db449ef
        ;;
e648291
    reload)
e648291
        usage
e648291
        # unimplemented feature
9c63bd9
        exit 3
e648291
        ;;
db449ef
    configtest)
db449ef
        configtest
db449ef
        ;;
db449ef
    status)
9c63bd9
        rh_status
db449ef
        ;;
db449ef
    *)
e648291
        usage
9c63bd9
        exit 2
db449ef
        ;;
db449ef
esac
db449ef
9c63bd9
exit $?