#!/sbin/runscript # Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ opts="configtest" DHCPD_CONF=${DHCPD_CONF:-/etc/dhcp/dhcpd.conf} DHCPD6_CONF=${DHCPD6_CONF:-/etc/dhcp/dhcpd6.conf} depend() { need net use logger dns } get_var() { sed -n 's/^[[:blank:]]\?'"$1"' "*\([^#";]\+\).*/\1/p' \ "${DHCPD_CHROOT}/${DHCPD_CONF}" } get_var6() { sed -n 's/^[[:blank:]]\?'"$1"' "*\([^#";]\+\).*/\1/p' \ "${DHCPD_CHROOT}/${DHCPD6_CONF}" } checkconfig() { if [ -f "${DHCPD_CHROOT}/${DHCPD_CONF}" ] ; then /usr/sbin/dhcpd -cf ${DHCPD_CHROOT}/${DHCPD_CONF} -t 1 -4 >/dev/null 2>&1 ret=$? if [ $ret -ne 0 ]; then eerror "${SVCNAME} has detected a syntax error in your configuration files:" /usr/sbin/dhcpd -cf ${DHCPD_CHROOT}/${DHCPD_CONF} -t -4 fi fi if [ -f "${DHCPD_CHROOT}/${DHCPD_CONF6}" ] ; then /usr/sbin/dhcpd -cf ${DHCPD_CHROOT}/${DHCPD6_CONF} -t 1 -6 >/dev/null 2>&1 ret=$? if [ $ret -ne 0 ]; then eerror "${SVCNAME}6 has detected a syntax error in your configuration files:" /usr/sbin/dhcpd -cf ${DHCPD_CHROOT}/${DHCPD6_CONF} -t -6 fi fi return $ret } configtest() { ebegin "Checking ${SVCNAME} configuration" checkconfig eend $? } start() { # Work out our cffile if it's on our DHCPD_OPTS case " ${DHCPD_OPTS} " in *" -cf "*) DHCPD_CONF=" ${DHCPD_OPTS} " DHCPD_CONF="${DHCPD_CONF##* -cf }" DHCPD_CONF="${DHCPD_CONF%% *}" ;; *) DHCPD_OPTS="${DHCPD_OPTS} -cf ${DHCPD_CONF}" ;; esac case " ${DHCPD6_OPTS} " in *" -cf "*) DHCPD6_CONF=" ${DHCPD6_OPTS} " DHCPD6_CONF="${DHCPD6_CONF##* -cf }" DHCPD6_CONF="${DHCPD6_CONF%% *}" ;; *) DHCPD6_OPTS="${DHCPD6_OPTS} -cf ${DHCPD6_CONF}" ;; esac if [ ! -f "${DHCPD_CHROOT}/${DHCPD_CONF}" ] && [ ! -f "${DHCPD_CHROOT}/${DHCPD6_CONF}" ] ; then eerror "${DHCPD_CHROOT}/${DHCPD_CONF} and/or ${DHCPD_CHROOT}/${DHCPD6_CONF} does not exist, you need at least one!" return 1 fi checkconfig || return 1 # Setup LD_PRELOAD so name resolution works in our chroot. if [ -n "${DHCPD_CHROOT}" ] ; then LD_PRELOAD="${LD_PRELOAD} /usr/lib/libresolv.so" export LD_PRELOAD="${LD_PRELOAD} /usr/lib/libnss_dns.so" fi if [ -f "${DHCPD_CHROOT}/${DHCPD_CONF}" ] ; then local leasefile="$(get_var lease-file-name)" leasefile="${DHCPD_CHROOT}/${leasefile:-/var/lib/dhcp/dhcpd.leases}" if [ ! -f "${leasefile}" ] ; then ebegin "Creating ${leasefile}" touch "${leasefile}" chown dhcp:dhcp "${leasefile}" eend $? || return 1 fi local pidfile="$(get_var pid-file-name)" pidfile="${pidfile:-/var/run/dhcp/dhcpd.pid}" ebegin "Starting ${DHCPD_CHROOT:+chrooted }${SVCNAME}" start-stop-daemon --start --exec /usr/sbin/dhcpd \ --pidfile "${DHCPD_CHROOT}/${pidfile}" \ -- ${DHCPD_OPTS} -q -pf "${pidfile}" -4 \ -user dhcp -group dhcp \ ${DHCPD_CHROOT:+-chroot} ${DHCPD_CHROOT} ${DHCPD_IFACE} eend $? \ && save_options chroot "${DHCPD_CHROOT}" \ && save_options pidfile "${pidfile}" fi if [ -f "${DHCPD_CHROOT}/${DHCPD6_CONF}" ] ; then local leasefile6="$(get_var6 lease-file-name)" leasefile6="${DHCPD_CHROOT}/${leasefile6:-/var/lib/dhcp/dhcpd6.leases}" if [ ! -f "${leasefile6}" ] ; then ebegin "Creating ${leasefile6}" touch "${leasefile6}" chown dhcp:dhcp "${leasefile6}" eend $? || return 1 fi local pidfile6="$(get_var6 pid-file-name)" pidfile6="${pidfile6:-/var/run/dhcp/dhcpd6.pid}" ebegin "Starting ${DHCPD_CHROOT:+chrooted }${SVCNAME}6" start-stop-daemon --start --exec /usr/sbin/dhcpd \ --pidfile "${DHCPD_CHROOT}/${pidfile6}" \ -- ${DHCPD6_OPTS} -q -pf "${pidfile6}" -6 \ -user dhcp -group dhcp \ ${DHCPD_CHROOT:+-chroot} ${DHCPD_CHROOT} ${DHCPD6_IFACE} eend $? \ && save_options chroot "${DHCPD_CHROOT}" \ && save_options pidfile6 "${pidfile6}" fi } stop() { local chroot="$(get_options chroot)" ebegin "Stopping ${chroot:+chrooted }${SVCNAME}" start-stop-daemon --stop --exec /usr/sbin/dhcpd \ --pidfile "${chroot}/$(get_options pidfile)" eend $? ebegin "Stopping ${chroot:+chrooted }${SVCNAME}6" start-stop-daemon --stop --exec /usr/sbin/dhcpd \ --pidfile "${chroot}/$(get_options pidfile6)" eend $? }