#!/bin/sh
#
# chkconfig: 345 91 50
# description: Starts and stops the bliss


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

# Avoid using root's TMPDIR
unset TMPDIR

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

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

start() {
    # Check if it is already running
	echo -n $"Starting bliss daemon: "
    if [ ! `pgrep -f /opt/bliss/bin/` ]; then
     daemon daemonize -E BLISS_MAX_HEAP=256M /opt/bliss/bin/bliss.sh
	else
     status bliss
    fi
	echo
	return $RETVAL

}


stop() {
	echo -n $"Stopping bliss daemon: "
	echo_success
	for i in `pgrep -f /opt/bliss/bin/`
	 do
	  kill $i
	 done
	echo

}

restart() {
        stop
        sleep 1
        start
}

checkstatus() {
	if [ ! `pgrep -f /opt/bliss/bin/` ]; then
	 echo -n $"bliss is stopped"
	 echo
	else
	  echo "bliss (pid `pgrep -f /opt/bliss/bin/`) is running..."
	fi 
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  status)
        checkstatus
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 2
esac
exit $?
