#!/bin/sh

SCRIPTSDIR="/scripts/snmp"

##############################################################################################
#
# This file is to be copied to /etc/init.d/ and then the following commands shoud be executed:
#
# ln -s /scripts/snmp/ich-collector /etc/rc2.d/S55ich-collector
# ln -s /scripts/snmp/ich-collector /etc/rc3.d/S55ich-collector
#
##############################################################################################

PROCESSORCOLLECTOR="collect-processor-stats.sh"
XMCOLLECTOR="collect-xm-stats.sh"
DISKCOLLECTOR="collect-disk-stats.sh"

RET=0

start() {
    echo -n "Starting ich-collector........ "
    $SCRIPTSDIR/$PROCESSORCOLLECTOR &
    $SCRIPTSDIR/$DISKCOLLECTOR &
    if [ -e /usr/sbin/xm ]; then
	# Xen Hypervisor
        $SCRIPTSDIR/$XMCOLLECTOR &
    fi
    RET=$?
    [ $RET -eq 0 ] && echo "[  OK  ]" || echo "[  FAIL  ]"
    return $RET
}

shut() {
     echo "This function doesn't work at the moment!"
#    echo "Stopping ich-collector: \c"
#    COLLECTOR_PID=`ps -ef |grep "zpool iostat" |grep -v grep |awk '{print $2}'`
#    if [ -z "$COLLECTOR_PID" ]; then
#        echo "FAILED, ich-collector is not running!"
#        exit 1
#    fi
#    kill $COLLECTOR_PID
#    RET=$?
#    [ $RET -eq 0 ] && echo "[  OK  ]" || echo "[ Fail ]"
#    return $RET
}

case "$1" in
    start)
        start
        ;;
    stop)
        shut
        ;;
    restart)
        echo "This function doesn't work at the moment!"
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $RET

