Blob Blame History Raw
#!/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
# config: /var/lib/dhcpd/dhcpd.leases
# pidfile: /var/run/dhcpd.pid

. /etc/rc.d/init.d/functions

RETVAL=0

prog=dhcpd
exec=/usr/sbin/dhcpd
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"
}

config="$(findConfig "$DHCPDARGS")"

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
    RETVAL=$?
    if [ $RETVAL -eq 1 ]; then
        $exec -t -cf $config
    else
        echo "Syntax: OK" >&2
    fi
    return $RETVAL
}

rh_status() {
    status -p $pidfile -l $(basename $lockfile) $exec
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

start() {
    [ `id -u` -eq 0 ] || return 4
    [ -x $exec ] || return 5
    [ -f $config ] || return 6

    rh_status_q && return 0

    echo -n $"Starting $prog: "
    daemon --pidfile=$pidfile $exec $DHCPDARGS 2>/dev/null
    RETVAL=$?

    echo
    [ $RETVAL -eq 0 ] && touch $lockfile
    return $RETVAL
}

stop() {
    [ `id -u` -eq 0 ] || return 4

    rh_status_q || return 0

    echo -n $"Shutting down $prog: "
    killproc -p $pidfile $prog
    RETVAL=$?

    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile
    return $RETVAL
}

usage() {
    echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
}

if [ $# -gt 1 ]; then
    exit 2
fi

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|force-reload)
        stop ; start
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        stop ; start
        ;;
    reload)
        usage
        # unimplemented feature
        exit 3
        ;;
    configtest)
        configtest
        ;;
    status)
        rh_status
        ;;
    *)
        usage
        exit 2
        ;;
esac

exit $?