#!/bin/sh

### BEGIN INIT INFO
# Provides:             netams4
# Required-Start:       $all
# Required-Stop:        $all
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    NETAMS4
### END INIT INFO

NAME=netams4
DESC="NETAMS4"
DAEMON="/usr/local/netams4/startup.sh"
set -e

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

. /lib/lsb/init-functions

RETVAL=0

case "$1" in
  start)
    echo -n "Starting $DESC: "
    $DAEMON
    RETVAL=$?
    echo "$NAME."
    ;;
  stop)
    echo -n "Stopping $DESC: "
    ps ax | grep java | grep netams | awk '{ system("kill " $1) }'
    RETVAL=$?
    echo "$NAME."
    ;;
  restart)
	$0 stop
	sleep 1
	$0 start
    ;;
  status)
    ps ax | grep java | grep netams 
    ;;
  *)
    echo "Usage: $NAME {start|stop|restart|status}"
    exit 1
    ;;

esac

exit $RETVAL
