#!/bin/bash
# /etc/init.d/hwsapmonitor
### BEGIN INIT INFO
# Provides: hwsapmonitor
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: hwsapmonitor initscript
# Description: This service is used to manage a led
### END INIT INFO

bpath=/usr/sap/sap_monitor/sap_monitor_script
svc=hwsapmonitor
bin=${svc}.py

case "$1" in
    start)
        echo "Starting $svc"
        su -s /bin/bash - $svc -c "cd $bpath; python $bpath/$bin & > /dev/null"
        ;;
    stop)
        echo "Stopping $svc"
        #killall zhbTest.py
        ps aux | grep "$bpath/$bin" |grep -v grep| cut -c 9-15 | xargs kill
        ;;
    status)
        pid=`ps aux | grep "$bpath/$bin" |grep -v grep| cut -c 9-15`
        if [ -n "$pid" ]
        then
            echo "$svc status:                                        running"
        else
            echo "$svc status:                                        unused"
        fi
        ;;
    *)
        echo "Usage: service $svc start|stop"
        exit 1
        ;;
esac
exit 0
