#!/bin/sh

set -e
DAEMON=$2
NAME=uos-license-agent
DAEMONUSER=root
PIDDIR=/usr/libexec/uos-license
PIDFILE=$PIDDIR/pid
DESC="system message uos-license-agent"
AGENTSTATUS=0

test -x $DAEMON || exit 0

agent_status()
{
	AgeProcNum=`ps -ef | grep $DAEMON | awk '$8=="'"${DAEMON}"'" {print $2}'`
    if [ x$AgeProcNum != x"" ]; then
        AGENTSTATUS=1
    fi
}

start_it_up()
{
    agent_status
    if [ $AGENTSTATUS -eq 0 ]; then
        nohup $DAEMON >> /dev/null 2>&1 &
    fi
}

case "$1" in
    start)
      start_it_up
    ;;
    stop)
      echo "Usage: /etc/.uos/license {start|stop|restart|status}" >&2
      exit 2
    ;;
    reload|force-reload)
      echo "Usage: /etc/.uos/license {start|stop|restart|status}" >&2
      exit 2
    ;;
    restart)
      echo "Usage: /etc/.uos/license {start|stop|restart|status}" >&2
      exit 2
    ;;
    status)
      #status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
      agent_status
      if [ $AGENTSTATUS -eq 0 ]; then
          echo "IS NOT RUNNING"
      else
          echo "IS RUNNING"
      fi
      ;;
    *)
      echo "Usage: /etc/.uos/license {start|status}" >&2
      exit 2
    ;;
esac


