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
db449ef
# config: /etc/dhcpd.conf
db449ef
# config: /var/lib/dhcpd/dhcpd.leases
db449ef
# pidfile: /var/run/dhcpd.pid
db449ef
db449ef
. /etc/init.d/functions
db449ef
db449ef
RETVAL=0
db449ef
db449ef
prog=dhcpd
db449ef
dhcpd=/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
db449ef
    echo "/etc/dhcpd.conf"
db449ef
}
db449ef
db449ef
conf="$(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() {
db449ef
    [ -x $dhcpd ] || return 5
db449ef
    [ -f $conf ] || return 6
db449ef
    $dhcpd -q -t -cf $conf
db449ef
    RETVAL=$?
db449ef
    return $RETVAL
db449ef
}
db449ef
db449ef
start() {
db449ef
    [ -x $dhcpd ] || return 5
db449ef
    [ -f $conf ] || return 6
db449ef
db449ef
    pidofproc $prog >/dev/null 2>&1
db449ef
    RETVAL=$?
db449ef
    [ $RETVAL -eq 0 ] && return $RETVAL
db449ef
db449ef
    echo -n $"Starting $prog: "
db449ef
    daemon $dhcpd $DHCPDARGS 2>/dev/null
db449ef
    RETVAL=$?
db449ef
    echo
db449ef
    [ $RETVAL = 0 ] && touch $lockfile
db449ef
    return $RETVAL
db449ef
}
db449ef
db449ef
stop() {
db449ef
    pidofproc $prog >/dev/null 2>&1
db449ef
    if [ $? -ne 0 ]; then
db449ef
        RETVAL=7
db449ef
        return $RETVAL
db449ef
    fi
db449ef
db449ef
    echo -n $"Shutting down $prog: "
db449ef
    killproc $prog
db449ef
    RETVAL=$?
db449ef
db449ef
    [ $RETVAL = 0 ] && success || failure
db449ef
    echo
db449ef
    [ $RETVAL = 0 ] && rm -f $lockfile
db449ef
    return $RETVAL
db449ef
}
db449ef
db449ef
if [ $# -gt 1 ]; then
db449ef
    RETVAL=2
db449ef
    exit $RETVAL
db449ef
fi
db449ef
db449ef
case "$1" in
db449ef
    start)
db449ef
        start
db449ef
        RETVAL=$?
db449ef
        ;;
db449ef
    stop)
db449ef
        stop
db449ef
        RETVAL=$?
db449ef
        ;;
db449ef
    restart|force-reload)
db449ef
        stop ; start
db449ef
        RETVAL=$?
db449ef
        ;;
db449ef
    try-restart|reload)
db449ef
        RETVAL=3
db449ef
        ;;
db449ef
    condrestart)
db449ef
        if [ -f $lockfile ]; then
db449ef
            stop ; start
db449ef
            RETVAL=$?
db449ef
        fi
db449ef
        ;;
db449ef
    configtest)
db449ef
        configtest
db449ef
        RETVAL=$?
db449ef
        ;;
db449ef
    status)
db449ef
        status $dhcpd
db449ef
        RETVAL=$?
db449ef
        ;;
db449ef
    *)
db449ef
        echo $"Usage: $0 {start|stop|restart|condrestart|configtest|status}"
db449ef
        RETVAL=3
db449ef
        ;;
db449ef
esac
db449ef
db449ef
exit $RETVAL