#!/bin/sh
#
# /etc/rc.d/init.d/atm  -  Bring up/down ATM
#

# Source function library.
. /etc/rc.d/init.d/functions

if [ ! -f /etc/sysconfig/atm ]; then
    exit 0
fi

. /etc/sysconfig/atm

[ "$ATM" != yes ] && exit 0

cd /etc/sysconfig/network-scripts

case "$1" in
    start)
	echo -n "Starting ATM demons: "
	daemon atmsigd -b -l syslog -D /var/tmp -t 20
	daemon ilmid -b -l syslog `[ -z "$ILMIQOS" ] || echo -q $ILMIQOS`
	sleep 3 # let's rest a second give signalling and ilmid a chance to get started.
	if [ "$LANE" = yes ]; then
		for i in /etc/sysconfig/network-scripts/ifcfg-lec[0-9]; do
			source $i
			zeppelin -n $ELAN -i $INTERFACEID -l $SELBYTE -F syslog & 
		done
	fi
	[ "$IPATM" = yes ] && daemon atmarpd -b -l syslog -m
	# launch LANE demon(s) ...
	[ "$AREQUIPA" = yes ] && daemon arequipad -b -l syslog
	echo
	touch /var/lock/subsys/atm
	;;
    stop)
	if [ "$LANE" = yes ]; then
	    for n in ifcfg-lec[0-9]; do
		./ifdown $n
		killproc zeppelin
	    done
	fi
	if [ "$IPATM" = yes ]; then
	    for n in ifcfg-atm[0-9]; do
		./ifdown $n
	    done
	fi
	echo -n "Stopping ATM demons: "
	if [ "$IPATM" = yes ]; then
	    [ "$AREQUIPA" = yes ] && killproc arequipad
	    killproc atmarpd
	fi
	killproc atmsigd	# kill ILMID later, so we don't get complaints
	killproc ilmid
	echo
	rm -f /var/lock/subsys/atm
	;;
    *)	echo "Usage: atm {start|stop}"
	exit 1
esac
