#!/bin/bash
# chkconfig: 2345 20 80
# description: Vanta's monitoring agent

if [ -e /etc/init.d/functions ]; then
  . /etc/init.d/functions
fi

RUN_PATH=/var/vanta/metalauncher
PID_FILE=/var/run/vanta.pid
PGID_FILE=/var/run/vanta.pgid

case "$1" in
start)
   nohup $RUN_PATH >/dev/null 2>&1 &
   VANTA_PID=$!
   echo $VANTA_PID > $PID_FILE
   ps -o pgid= $VANTA_PID > $PGID_FILE
   ;;
stop)
   kill -- -`cat $PGID_FILE | sed -e 's/\s*//g'`
   rm $PID_FILE $PGID_FILE
   ;;
restart)
   $0 stop
   $0 start
   ;;
status)
   if [ -e $PGID_FILE ]; then
      echo vanta is running, pid=`cat $PID_FILE`, pgid=`cat $PGID_FILE`
   else
      echo vanta is NOT running
      exit 1
   fi
   ;;
*)
   echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0
