#!/bin/bash
# /etc/init.d/hwdataprovider
### BEGIN INIT INFO
# Provides: hwdataprovider
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Short-Description: hwdataprovider initscript
# Description: The SAP data provider (for SAP certification/support)
### END INIT INFO

bpath=/opt/otc/dataprovider
svc=dataprovider
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 "/opt/.*/$bin" |grep -v grep| cut -c 9-15 | xargs kill
	true
        ;;
    restart)
	$0 stop
	$0 start
	;;
    condrestart|try-restart|reload)
	$0 status || exit 0
	$0 stop
	$0 start
	;;
    status)
        pid=`ps aux | grep "/opt/.*/$bin" |grep -v grep| cut -c 9-15`
        if [ -n "$pid" ]
        then
            echo "$svc status: $pid                                  running"
	    exit 0
        else
            echo "$svc status:                                        unused"
            exit 3
        fi
        ;;
    *)
        echo "Usage: service $svc start|stop"
        exit 1
        ;;
esac
