#!/bin/bash
################################################################################
# Filename: ./src/plugins/dhcpd/etc/init.d/dhcpd
# 
# The contents of this file are subject to the Qlusters Public License
# Version 1.1 (the License); you may not use this file except in compliance
# with the License.
# You may obtain a copy of the License at
# http://www.openqrm.org/content/view/33/69/.
# 
# Software distributed under the License is distributed on an AS IS basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
# the specific language governing rights and limitations under the License.
# 
# The Original Code is openQRM.
# 
# The Initial Developer of the Original Code is Qlusters Corporation. Portions
# created by Qlusters Corporation are Copyright (C) 2003-2005. All Rights
# Reserved.
# 
# Contributor(s):
# 
# Description:
# 
# Comments:
################################################################################
# init script for the dhcpd plugin

QRM_SERVER_BASE_DIR=`readlink /etc/init.d/qrm-server | sed -e "s#/qrm/etc/init.d/qrm-server##g"`
PLUGIN_BASE_DIR=$QRM_SERVER_BASE_DIR/qrm/plugins/dhcpd

function start() {
	echo "starting Qrm dhcpd plugin"
	$PLUGIN_BASE_DIR/sbin/dhcpd -cf $PLUGIN_BASE_DIR/etc/dhcpd.conf -lf $PLUGIN_BASE_DIR/var/state/dhcp/dhcpd.leases 1>>/var/log/messages 2>&1
}


function stop() {
	echo "stopping Qrm dhcpd plugin"
	for DHCPD_PID in `ps -C dhcpd 2>&1 | grep -v PID | awk {' print $1 '}`; do
		if [ "$DHCPD_PID" != "$$" ]; then
			kill $DHCPD_PID 1>/dev/null 2>&1
		fi
	done
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 1
		start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1

esac
exit $?


