#!/bin/sh
#
# Start App	
#
#
APPNAME=Display_GSM
APPBIN=/var/psg/Display_GSM.sh
echo $APPBIN
case "$1" in
  start)
        echo -e "Starting ${APPNAME} ...\n"
	if [ ! -f ${APPBIN} ]; then
		echo -e "Program ${APPBIN} doesn't exist \n"
		exit 1
	fi 
        screen -dmS ${APPNAME} sh -c "while true; do ${APPBIN}; echo '${APPNAME} stopped--> restart'; sleep 2;done"
        exit 0
        ;;
  stop)
        echo -e "Stopping ${APPNAME} ...\n"
        KILLPID=`screen -list | grep ${APPNAME} | awk -F'.' '{print $1}'`
        if [ ${#KILLPID} != "0" ]
                then
                kill $KILLPID
         fi
         exit 0
        ;;
  restart|reload)
        "$0" stop
        "$0" start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?

