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

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

case "$1" in
    start)
        echo "Starting $svc"
        su -s /bin/bash - hwsapmonitor -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 $serviceupdatename start|stop"
        exit 1
        ;;
esac
exit 0
