#!/bin/bash
#chkconfig: 2345 50 46 
#description: Chelsio Uwire Manager Agent Port 

### BEGIN INIT INFO
# Provides:          Chelsio_Uwire_Manager_PortPersistent
# Required-Start:    $network
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 2 6
# Short-Description: Chelsio Unified Wire Manager Agent Daemon
# Description:       The Chelsio Unified Wire Manager Agent daemon 
#	service.  We want it to be active in runlevels 2 3 4
#	and 5, as these are the runlevels with the network
#	available.
### END INIT INFO

RETVAL=0
prog="Chelsio Uwire Manager Agent Port Persistenent"
EXP_INSTANCE=0
instance=0
SNMP_INSTANCE=1
BIN_PATH="/opt/chelsio/uwire_mgmt/agent/setPortAtInit"
start_uwireserver()
{

        echo -n $"Starting $prog: "
	
	$BIN_PATH
	RETVAL=$?
	if [ $RETVAL -eq 0 ];
         then
                echo -e '\E[0;32m \t\t\t[OK] \E[m';
        else
                echo -e '\E[0;31m \t\t\t[Failed]\E[m';
        fi
        return $RETVAL

}

stop_uwireserver() {
        # echo -n $"Stopping $prog: "
 
	instance=$(ps -eaf | grep UWMgrServer | grep -v grep | wc -l )
			
		if [ $instance -eq 1 ]; then
		    pid=$( ps -eaf | grep UWMgrServer | grep -v grep | awk '{print $2}' )
		    kill -9 $pid
		     echo " Unified Wire Manager Agent is now stopped"
		else
		     echo " Unified Wire Manager Agent is not running"
		fi
			
               
	RETVAL=$?
        return $RETVAL
}



if [ $UID -ne 0 ]; then
    echo "chelsio-uwire_portd: Permission denied: Not a root user"
    exit 0
fi

case "$1" in
  start)
	start_uwireserver
	;;
  *)
	echo $"Usage: $0 {start}"
	RETVAL=1
esac

exit $RETVAL
