#!/bin/sh
# DBS Telephony Server Copyright (c) 1997-1998 Tycho Softworks.
# $Id: dbs.init 1.3 Mon, 26 Oct 1998 08:33:49 -0500 dyfet $

DBS_PATH=/usr/sbin
PATH=$PATH:$DBS_PATH
BASENAME=`basename $0 | sed s/^S[0-9][0-9]// | sed s/\.init//`
PREFIX=''

# Source function library.
if test -f /etc/rc.d/init.d/functions ; then
	. /etc/rc.d/init.d/functions
else
	PREFIX=$BASENAME'-'
fi

# Source networking configuration.
if test -d /etc/sysconfig ; then
	if test ! -f /etc/sysconfig/network ; then
   		 exit 0
	fi

	. /etc/sysconfig/network

	# Check that networking is up.
	[ ${NETWORKING} = "no" ] && exit 0
fi

# Determine startup type
if test -z "$1" ; then
	cmd=$BASENAME
else
	cmd=$PREFIX$1
fi

if test -z "$LANG" ; then
	LANG=C
	export LANG
fi

# See how we were called.
case "$cmd" in
  dbs-start | rc.dbs)
	echo -n "starting dbs services(s): "
	dbs_server -D
	echo -n dbs_server
	echo
	;;
  start)
	echo -n "Starting dbs service(s): "
	dbs_server -D
	echo -n dbs_server
	echo
	if test -d /var/lock/subsys ; then
		touch /var/lock/subsys/dbs
	fi
	;;
  dbs-stop)
	echo -n "Stopping telephony protocols: "
	nice 10
	echo -n "stopping dbs service(s): "
	for dn in dbs_server ; do
                pids=`ps -e | grep $dn | cut -d\  -f 2`
                if test ! -z "$pids" ; then
                        for pid in $pids ; do
                                kill $pid
                        done
                fi
                sleep 1
                pids=`ps -e | grep $dn | cut -d\  -f2`
                if test ! -z "$pids" ; then
                        for pid in $pids ; do
                                kill -9 $pid
                        done
                fi
                echo -n $proto
        done
        echo

	;;
  stop)
	echo -n "Stopping dbs service(s): "
	kill `pidofproc dbs_server`
	echo -n dbs_server
	if test -f /var/lock/subsys/dbs ; then
		rm /var/lock/subsys/dbs
	fi
	echo
	;;
  status)
	status dbs
	;;
  restart | dbs-restart)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: dbs {start|stop|restart|status}"
	exit 1
esac

exit 0

