#!/bin/sh
# @(#) ovpa bootup      11.00.020       25FEB2010 Linux 
#
# chkconfig: 2345 96 8
# description: HP Performance Agent 11.00.020
#
#
# NOTE:    Changes to the startup behavior of  HP Performance Agent can
#          be made by modifying the ovpa configuration script
#          (/etc/sysconfig/ovpa or /etc/ovpa.conf depending on the platform)
#          which is executed by this script and sets the following variables:
#
#             OVPA_START           (flag to start MeasureWare or not)
#             OVPA_START_COMMAND   (startup command for MeasureWare)
#
#
# NOTE:    This script is not configurable!  Any changes made to this
#          script will be overwritten when you upgrade to the next
#          release of HP Performance Agent.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
#
# ---------------------------------------------------------------------------
# This script will start up (or shut down) the scopeux collection daemon
# for the HP Performance Agent product.
#

# Allowed exit values:
#       0 = success; causes "OK" to show up in checklist.
#       1 = failure; causes "FAIL" to show up in checklist.
#       2 = skip; causes "N/A" to show up in the checklist.
#           Use this value if execution of this script is overridden
#           by the use of a control variable, or if this script is not
#           appropriate to execute for some other reason.
#       3 = reboot; causes the system to be rebooted after execution.

# Input and output:
#       stdin is redirected from /dev/null
#
#       stdout and stderr are redirected to the /etc/rc.log file
#       during checklist mode, or to the console in raw mode.

# NOTE: If your script executes in run state 0 or state 1, then /usr might
#       not be available.  Do not attempt to access commands or files in
#       /usr unless your script executes in run state 2 or greater.  Other
#       file systems typically not mounted until run state 2 include /var
#       and /opt.
#------------------------------------------------------
#The following commented lines are required for SUSE LINUX to update the 
#.depend.start and .depend.stop in /etc/init.d/ directory. This is required to
#auto start ovpa upon machine restart. 
### BEGIN INIT INFO
# Provides: ovpa
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $ALL
# Should-Stop: $ALL
# Default-Start: 2 3 5
# Default-Stop: 0 6
# Description: Start the ovpa application
### END INIT INFO

if [ -d /etc/sysconfig ]; then

  CONFIGFILE="/etc/sysconfig/ovpa"
else
  CONFIGFILE="/etc/ovpa"
fi

PATH=/sbin:/bin
export PATH
OVPA_BOOT=1
export OVPA_BOOT
rval=0

# Check the exit value of a command run by this script.  If non-zero, the
# exit code is echoed to the log file and the return value of this script
# is set to indicate failure.

set_return() {
        x=$?
        if [ $x -ne 0 ]; then
                echo "EXIT CODE: $x"
                rval=1  # script FAILed
        fi
}

case $1 in
'start_msg')
        echo " HP Performance Agent software is being started."
        ;;

'stop_msg')
        echo "Shutting down  HP Performance Agent software"
        ;;

'start')
               # source the Perf Agent configuration variables
               if [ -f $CONFIGFILE ] ; then
                       . $CONFIGFILE 
               else
                       echo "ERROR: $CONFIGFILE file MISSING"
               fi

               if [ -f /var/opt/perf/datafiles/OVPA_RUN ]
               then
                  rm -f /var/opt/perf/datafiles/OVPA_RUN
               fi
              
               if [ -f /var/opt/perf/.vima ]; then
                 if [ ! -f /etc/ld.so.conf.d/VIdaemon.conf ]; then
                    echo /opt/vmware/vma/lib64 >> /etc/ld.so.conf.d/VIdaemon.conf
                    echo /opt/vmware/vma/lib >> /etc/ld.so.conf.d/VIdaemon.conf
                    if [ -x /sbin/ldconfig ]; then
                      /sbin/ldconfig
                    fi
                 fi
               fi

               # Check to see if this script is allowed to run...
               if [ "$OVPA_START" != 1 ]; then
                       rval=2
               else
                 if [ -x /opt/perf/bin/ovpa ]
                 then
                   if [ "$OVPA_START_COMMAND" != "" ]
                   then
                     eval $OVPA_START_COMMAND
                   else
                     /opt/perf/bin/ovpa start 2>&1 > /dev/null 
                   fi
                 fi
               fi
               ;;

'stop')
               if [ -x /opt/perf/bin/ovpa ] 
               then
                 /opt/perf/bin/ovpa stop fast
                 /opt/perf/bin/ttd -k
                 sleep 5
               fi
               ;;

'restart')
               if [ -x /opt/perf/bin/ovpa ]
               then
                  /opt/perf/bin/ovpa restart
               fi
               ;;

'force-reload')
               if [ -x /opt/perf/bin/ovpa ]
               then
                 /opt/perf/bin/ovpa restart
               fi
               ;;

'status')      if [ -x /opt/perf/bin/ovpa ]
               then
                 /opt/perf/bin/ovpa status
               fi
               ;;

*)
        echo "usage: $0 {start|stop|restart|force-reload|status|start_msg|stop_msg}"
        rval=1
        ;;
esac

exit $rval
