#!/bin/sh /etc/rc.common

START=70

pidfile=/var/run/babel.pid

babel_config() {
	local cfg="$1"
	config_get interfaces "$cfg" interfaces
}

start() {
	if [ -x /etc/init.d/ahcpd ] ; then
		echo 'Not starting babel -- will be started by ahcpd.'
		exit 0
	fi
	config_load babel
	config_foreach babel_config babel
	mkdir -p /var/lib
	if [ -e $pidfile ] ; then
		echo "$pidfile exists -- not starting babel." >&2
	else
		/usr/bin/babel -D -I $pidfile $interfaces
	fi
}

stop() {
	[ -e $pidfile ] && kill $(cat $pidfile)
	[ -e $pidfile ] && sleep 2
	[ -e $pidfile ] && sleep 4
	[ -e $pidfile ] && echo "Failed to stop ahcpd ($pidfile still exists)."
}
