#! /bin/sh
# --------------------------------------------------------------------

QUEUES="cellnet bteasyreach minicall"

# --------------------------------------------------------------------

SMSBINDIR=/usr/local/sbin
SMSD=${SMSBINDIR}/smsd
QUEUED=${SMSBINDIR}/queue
PIDDIR=/var/spool/sms/locks

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# --------------------------------------------------------------------

if [ ! -f "$SMSD" ]
then
	exit 0
fi

if [ ! -f "$QUEUED" ]
then
	exit 0
fi

case "$1" in
	start)
		echo -n "Starting SMS Daemon: "

		if [ -f "$SMSD" ]
		then
			$SMSD 2>/dev/null >/dev/null
			echo -n "smsd"
		fi
		echo

		echo -n "Starting SMS Queue Daemons: "
		for queue in `$QUEUED -a`
		do
			echo -n "$queue "
		done
		echo

		;;
	stop)
		echo -n "Stopping SMS Queue Daemons: "

		for queue in `$QUEUED -a`
		do
			if [ -f "${PIDDIR}/${queue}.pid" ]
			then
				SMSDPID=`cat ${PIDDIR}/${queue}.pid | awk '{ print \$1 }'`
				kill -TERM $SMSDPID

				echo -n "$queue "
			fi
		done
		echo


		echo -n "Stopping SMS Daemon: "

		if [ -f "${PIDDIR}/smsd.pid" ]
		then
			SMSDPID=`cat ${PIDDIR}/smsd.pid | awk '{ print \$1 }'`
			kill -TERM $SMSDPID

			echo -n "smsd"
		fi
		echo
		;;
	*)
		echo "Usage: smsd {start|stop}" 1>&2
		exit 1
		;;
esac

exit 0
