#!/bin/sh
#
# zaptel	zaptel modules
#
# chkconfig:	345 85 15
# description:	Zaptel is a series of telephony interface devices often \
#   used with Asterisk
#

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

# Get service config
[ -f /etc/sysconfig/zaptel ] && . /etc/sysconfig/zaptel

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/zaptel ]; then
		msg_starting zaptel
		busy
		for mod in $ZAP_MODULES; do
			modprobe $mod
		done
		sleep 2
		/sbin/ztcfg
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zaptel
		ok
	else
		msg_already_running zaptel
	fi
}

stop() {
	# Stop daemons.
	if [ -f /var/lock/subsys/zaptel ]; then
		msg_stopping zaptel
		busy
		for mod in $ZAP_MODULES; do
			if test x$mod != xzaptel; then
				rmmod $mod
			fi
		done
		rmmod zaptel
		rm -f /var/lock/subsys/zaptel >/dev/null 2>&1
		ok
	else
		msg_not_running zaptel
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
	RETVAL=0
	;;
  restart)
  	stop
	start
	;;
  reload|force-reload|graceful)
	if [ -f /var/lock/subsys/zaptel ]; then
		/sbin/ztcfg
		RETVAL=$?
	else
		msg_not_running zaptel
		RETVAL=7
	fi
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|status}"
	exit 3
	;;
esac

exit $RETVAL
