#!/bin/sh
#
#chkconfig: 345 98 98
#description: start/stop all cobra service
#processname: cobrastatus
#
source /etc/rc.d/init.d/functions
#if [ ! -f /etc/init.d/mysqld ];
#then
#	echo "Plesae ensure mysql had been installed!"
#	exit 1
#elif [ ! -f /etc/init.d/sendmail ];
#then
#	echo "Please ensure sendmail had benn installed!"
#	exit 1
if [ ! -f /etc/init.d/CobraApi ];
then
	echo "Plesae ensure CobraApi had been installed!"
        exit 1
#elif [ ! -f /etc/init.d/mule ];
#then 
 #       echo "Plesae ensure mule had been installed!"
  #      exit 1
#elif [ ! -f /etc/init.d/tomcat6 ];
#then
 #       echo "Plesae ensure tomcat6 had been installed!"
  #      exit 1
elif [ ! -f /etc/init.d/ido2db ];
then
        echo "Plesae ensure ido2db had been installed!"
        exit 1
elif [ ! -f /etc/init.d/icinga ];
then
        echo "Plesae ensure icinga had been installed!"
        exit 1
elif [ ! -f /etc/init.d/nrpe ];
then
        echo "Plesae ensure nrpe had been installed!"
        exit 1

fi
status(){
#	/etc/init.d/mysqld status
#	/etc/init.d/sendmail status
	/etc/init.d/CobraApi status
#	/etc/init.d/mule status
#	/etc/init.d/tomcat6 status
	/etc/init.d/ido2db status
	/etc/init.d/icinga status
	/etc/init.d/nrpe status
}

start(){
	if [ -e /opt/cobra/icinga/var/ido2db.lock ] && [ -e /opt/cobra/icinga/var/ido.sock ];then
		rm -f /opt/cobra/icinga/var/ido2db.lock
		rm -f /opt/cobra/icinga/var/ido.sock
	fi
#	/etc/init.d/mysqld start
#	/etc/init.d/sendmail start
	/etc/init.d/CobraApi start
#       service mule start
#        /etc/init.d/tomcat6 start
        /etc/init.d/ido2db start
        /etc/init.d/icinga start
        /etc/init.d/nrpe start

}

stop(){
        /etc/init.d/nrpe stop
        /etc/init.d/icinga stop
        /etc/init.d/ido2db stop
 #       service mule stop
        /etc/init.d/CobraApi stop
#	/etc/init.d/sendmail stop
#	echo "mysql and tomcat will not be stopped!"
}

restart(){
        /etc/init.d/nrpe stop
        /etc/init.d/icinga stop
        /etc/init.d/ido2db stop
#       service mule stop
        /etc/init.d/CobraApi stop        
#	/etc/init.d/tomcat6 stop
#	/etc/init.d/sendmail stop
#       /etc/init.d/mysqld stop
	start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  status)
        status
        ;;

  *)
        echo $"Usage: $0 {start|stop|restart|status}"
esac
exit 0

