#!/bin/sh
#
# cdevGateway    This shell script takes care of starting and stopping
#                cdevGateway.
#
# chkconfig: 2345 60 60
# description: cdevGateway is the daemon required for JAVA/CDEV to work properly.

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

# Source networking configuration.
. /etc/sysconfig/network

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

[ -f /usr/local/i386-glibc22-linux/cdev-1.7.2/lib/cdev-setup.sh ] || exit 0
. /usr/local/i386-glibc22-linux/cdev-1.7.2/lib/cdev-setup.sh

[ -f $CDEV/sbin/cdevGateway.sh ] || exit 0

PATH=$CDEV/bin/$SYSNAME:$CDEV/sbin:/usr/bin:/usr/sbin:/bin:/sbin

# See how we were called.
case "$1" in
  start)
        
        # make sure log file exists and has the right ownership
        touch /var/log/cdevGateway.log
        chown nobody.nobody /var/log/cdevGateway.log
        # Start daemons.

        echo -n "Starting cdevGateway: "
	if [ ! -f /var/run/rsvcServer.pid ] ;then
	  echo -n "rsvcServer "
	  Pidgen="`su nobody -l -c $CDEV/sbin/rsvcServer.sh`"
	  echo -n $Pidgen >/var/run/rsvcServer.pid
	  logger -p local5.info -t "rsvcServer[$Pidgen]" "CDEV generic server started."
	  sleep 2
	else
	  echo; status rsvcServer
	fi
	if [ ! -f /var/run/cdevGateway.pid ] ;then
	  echo -n "cdevGateway"
	  Pidgat="`su nobody -l -c $CDEV/sbin/cdevGateway.sh`"
	  echo -n $Pidgat >/var/run/cdevGateway.pid
	  logger -p local5.info -t "cdevGateway[$Pidgat]" "CDEV gateway server started."
	else
	  echo; status cdevGateway
        fi
        touch /var/lock/subsys/cdevGateway
	sleep 1
        pidof cdevGateway >/dev/null 2>&1 && success "cdevGateway startup" || failure "cdevGateway startup"
        echo
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down cdevGateway: "
	killproc cdevGateway
	killproc rsvcServer
        echo
        rm -f /var/lock/subsys/cdevGateway
        ;;
  status)
	status rsvcServer
	status cdevGateway
	;;
  restart)
	$0 stop
	$0 start
	;;
  *)
        echo "Usage: cdevGateway {start|stop|restart|status}"
        exit 1
esac

exit 0
