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