From e6a433a23b9399b3c14503606389757daa37934f Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Sep 26 2007 19:20:47 +0000 Subject: - Init script fixes for dhcpd and dhcrelay (#278601) --- diff --git a/dhcp.spec b/dhcp.spec index 1d096bb..af0aaa3 100644 --- a/dhcp.spec +++ b/dhcp.spec @@ -13,7 +13,7 @@ Summary: DHCP (Dynamic Host Configuration Protocol) server and relay agent Name: dhcp Version: 3.0.6 -Release: 5%{?dist} +Release: 6%{?dist} Epoch: 12 License: ISC Group: System Environment/Daemons @@ -431,6 +431,9 @@ fi %{_libdir}/libdhcp4client.a %changelog +* Wed Sep 26 2007 David Cantrell - 12:3.0.6-6 +- Init script fixes for dhcpd and dhcrelay (#278601) + * Mon Sep 10 2007 David Cantrell - 12:3.0.6-5 - Fix typos in ldap.c and correct LDAP macros (#283391) diff --git a/dhcpd.init b/dhcpd.init index bec2836..3836f36 100644 --- a/dhcpd.init +++ b/dhcpd.init @@ -1,37 +1,54 @@ -#!/bin/bash +#!/bin/sh +# +### BEGIN INIT INFO +# Provides: dhcpd +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# 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 provide access to Dynamic Host Control Protocol. +# description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP) \ +# server +# processname: dhcpd +# config: /etc/dhcpd.conf +# config: /var/lib/dhcpd/dhcpd.leases +# pidfile: /var/run/dhcpd.pid -# Source function library. . /etc/init.d/functions RETVAL=0 + prog=dhcpd dhcpd=/usr/sbin/dhcpd lockfile=/var/lock/subsys/dhcpd +pidfile=/var/run/dhcpd.pid -. /etc/sysconfig/dhcpd - -cfOption() { - let i=0 - for a in $* ; do - ((++i)) - if [ $a = -cf ]; then - ((++i)) - eval 'echo $'$i - elif [[ $a = -cf* ]]; then - echo ${a#-cf} +[ -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/dhcpd.conf" } -CF=`cfOption $DHCPDARGS` -if [ -z "$CF" ]; then - CF='/etc/dhcpd.conf' -fi - -[ -f "$CF" ] || exit 0 +conf="$(findConfig "$DHCPDARGS")" if [ ! -f /var/lib/dhcpd/dhcpd.leases ] ; then mkdir -p /var/lib/dhcpd @@ -41,15 +58,20 @@ fi configtest() { [ -x $dhcpd ] || return 5 - [ -f $CF ] || return 6 - $dhcpd -q -t -cf $CF + [ -f $conf ] || return 6 + $dhcpd -q -t -cf $conf RETVAL=$? return $RETVAL } start() { [ -x $dhcpd ] || return 5 - [ -f $CF ] || return 6 + [ -f $conf ] || return 6 + + pidofproc $prog >/dev/null 2>&1 + RETVAL=$? + [ $RETVAL -eq 0 ] && return $RETVAL + echo -n $"Starting $prog: " daemon $dhcpd $DHCPDARGS 2>/dev/null RETVAL=$? @@ -59,42 +81,60 @@ start() { } stop() { + pidofproc $prog >/dev/null 2>&1 + if [ $? -eq 0 ]; then + RETVAL=7 + return $RETVAL + fi + echo -n $"Shutting down $prog: " killproc $prog RETVAL=$? + + [ $RETVAL = 0 ] && success || failure echo [ $RETVAL = 0 ] && rm -f $lockfile return $RETVAL } -# See how we were called. +if [ ! -x $dhcdbd ]; then + RETVAL=5 + exit $RETVAL +fi + +if [ $# -gt 1 ]; then + RETVAL=2 + exit $RETVAL +fi + case "$1" in start) start + RETVAL=$? ;; stop) stop + RETVAL=$? ;; - reload) - RETVAL=3 + restart|force-reload) + stop && start + RETVAL=$? ;; - restart) - configtest || exit $? - stop - start + try-restart|reload) + RETVAL=3 ;; condrestart) if [ -f $lockfile ]; then - stop - start + stop && start + RETVAL=$? fi ;; - configtest|check|testconfig|test) + configtest) configtest RETVAL=$? ;; status) - status $prog + status $dhcpd RETVAL=$? ;; *) diff --git a/dhcrelay.init b/dhcrelay.init index 425a89d..dabfe5a 100644 --- a/dhcrelay.init +++ b/dhcrelay.init @@ -1,23 +1,58 @@ -#!/bin/bash +#!/bin/sh +# +### BEGIN INIT INFO +# Provides: dhcrelay +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Should-Start: +# Required-Start: $network +# Required-Stop: +# Short-Description: Start and stop the DHCP relay server +# Description: dhcrelay provides the Dynamic Host Configuration Protocol (DHCP) +# relay server. This is required when your DHCP server is on +# another network segment from the clients. +### END INIT INFO +# +# The fields below are left around for legacy tools (will remove later). # # chkconfig: - 66 34 # description: dhcrelay provides a relay for Dynamic Host Control Protocol. +# processname: dhcrelay +# # pidfile: /var/run/dhcrelay.pid -# Source function library . /etc/init.d/functions RETVAL=0 + prog=dhcrelay dhcrelay=/usr/sbin/dhcrelay lockfile=/var/lock/subsys/dhcrelay +pidfile=/var/run/dhcrelay.pid +conf=/etc/sysconfig/dhcrelay -start() { +# The dhcrelay daemon uses the sysconfig file for configuration information. +# There is no native configuration file for this program and you must specify +# its settings on the command line. +[ -f /etc/sysconfig/dhcrelay ] && . /etc/sysconfig/dhcrelay + +configtest() { [ -x $dhcrelay ] || exit 5 - [ -f /etc/sysconfig/dhcrelay ] || exit 6 - . /etc/sysconfig/dhcrelay + [ -f $conf ] || exit 6 [ -z "$DHCPSERVERS" ] && exit 6 + RETVAL=0 + return $RETVAL +} + +start() { + [ -x $dhcrelay ] || exit 5 + [ -f $conf ] || exit 6 + + pidofproc $prog >/dev/null 2>&1 + RETVAL=$? + [ $RETVAL -eq 0 ] && return $RETVAL + echo -n $"Starting $prog: " - daemon $dhcrelay $([ -n "$INTERFACES" ] && for int in $INTERFACES ; do echo -n " -i $int" ; done) $DHCPSERVERS + daemon $dhcrelay $([ -n "$INTERFACES" ] && for int in $INTERFACES ; do echo -n " -i $int" ; done) $DHCPSERVERS 2>/dev/null RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $lockfile @@ -25,41 +60,64 @@ start() { } stop() { + pidofproc $prog >/dev/null 2>&1 + if [ $? -eq 0 ]; then + RETVAL=7 + return $RETVAL + fi + echo -n $"Shutting down $prog: " killproc $prog -TERM RETVAL=$? + + [ $RETVAL = 0 ] && success || failure echo - [ $RETVAL -eq 0 ] && rm -f $lockfile + [ $RETVAL = 0 ] && rm -f $lockfile return $RETVAL } -# See how we were called. +if [ ! -x $dhcrelay ]; then + RETVAL=5 + exit $RETVAL +fi + +if [ $# -gt 1 ]; then + RETVAL=2 + exit $RETVAL +fi + case "$1" in start) start + RETVAL=$? ;; stop) stop + RETVAL=$? ;; - reload) - RETVAL=3 + restart|force-reload) + stop && start + RETVAL=$? ;; - restart) - stop - start + try-restart|reload) + RETVAL=3 ;; condrestart) if [ -f $lockfile ]; then - stop - start + stop && start + RETVAL=$? fi ;; + configtest) + configtest + RETVAL=$? + ;; status) status $prog RETVAL=$? ;; *) - echo $"Usage: $0 {start|stop|restart|condrestart|status}" + echo $"Usage: $0 {start|stop|restart|condrestart|configtest|status}" RETVAL=3 ;; esac