#! /bin/sh
# kannel	Startup script for the Kannel WAP and SMS Gateway
#
#		Written by Andres Seco <AndresSH@alamin.org> using
#		the skeleton provided by Miquel van Smoorenburg and
#		Ian Murdock in Debian GNU/Linux 2.1 (slink)
#		modified with paragraphs from diald startup script
#		in Debian GNU/Linux 2.2 (potato)
#		Modified from init script from alamin-server.
#
# Version:	@(#)kannel  1.0  19-Aug-2001  AndresSH@alamin.org
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMONA=/usr/sbin/bearerbox
DAEMONB=/usr/sbin/wapbox
NAMEA=bearerbox
NAMEB=wapbox
PIDA=kannel_bearerbox
PIDB=kannel_wapbox
DESC="Kannel WAP and SMS Gateway"
CONF=/etc/kannel/kannel.conf

test -f $DAEMONA || exit 0
test -f $DAEMONB || exit 0
test -f $CONF || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC:"
        start-stop-daemon --start --quiet \
            --pidfile /var/run/$PIDA.pid \
            --exec /usr/sbin/run_kannel_box \
            -- \
            --pidfile /var/run/$PIDA.pid \
            --no-extra-args \
            su -s /bin/sh -c "$DAEMONA -v 4 -- $CONF" kannel
	echo -n " $NAMEA"
        start-stop-daemon --start --quiet \
            --pidfile /var/run/$PIDB.pid \
            --exec /usr/sbin/run_kannel_box \
            -- \
            --pidfile /var/run/$PIDB.pid \
            --no-extra-args \
            su -s /bin/sh -c "$DAEMONB -v 4 -- $CONF" kannel
	echo -n " $NAMEB"
	echo "."
	;;
  stop)
	echo -n "Stopping $DESC:"
	start-stop-daemon --stop --quiet --oknodo \
		--pidfile /var/run/$PIDB.pid \
                --exec /usr/sbin/run_kannel_box
	echo -n " $NAMEB"
	start-stop-daemon --stop --quiet --oknodo \
		--pidfile /var/run/$PIDA.pid \
                --exec /usr/sbin/run_kannel_box
	echo -n " $NAMEA"
	echo "."
	;;
  reload|force-reload|restart)
	$0 stop
	sleep 2
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
