ssahani / rpms / dhcp

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