#!/bin/bash  
#  
# JYNGLTX
# chkconfig: 2345 99 01
# description: jingyunsd service, for communicating 

### BEGIN INIT INFO
# Provides:          JYNGLTX
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: jingyunsd service
# Description:      jingyunsd service, for communicating 
### END INIT INFO  

svr_name=""
jyn_install_path=/opt/bdfz/jyn
verstr=`cat $jyn_install_path/Config.ini|grep -v "Mon"|grep "Type"`
versub=`echo ${verstr#*.}`
verflag=`echo ${versub:1:1}`

versubsdk=`echo ${verstr##*.}`
verflagsdk=`echo ${versubsdk:2:1}`

get_svr_name() {
	if [ -f $jyn_install_path/JingyunsdIPCServer ]; then
		svr_name="JingyunsdIPCServer"
	elif [ -f $jyn_install_path/JingyunSdCtrlCenter ]; then
		svr_name="JingyunSdCtrlCenter"
	else
		svr_name="JYNGLTX1"
	fi
	echo "service name:[$svr_name]"
}

start() {  
	get_svr_name
	PID=`pidof $svr_name`
	if [ "$PID" = "" ] ; then
		nohup $jyn_install_path/$svr_name >/dev/null 2>&1  &
		echo "start $svr_name"
	else
		echo "$svr_name already running"
	fi
}  

stop() {  
	get_svr_name
	PID=`pidof $svr_name`
	if [ "$PID" = "" ] ; then
		echo "$svr_name not running"
	else
		kill -9 `pidof $svr_name`
	fi
}  

status(){
	get_svr_name
	PID=`pidof $svr_name`
	if [ "$PID" = "" ] ; then
		echo "$svr_name not running"
	else
		echo "$svr_name is running"
	fi
}

case "$1" in  
start)  
start  
;;  
stop)  
stop  
;;  
reload|restart)  
stop  
start  
;;  
status)  
status
;;  
*)  
echo $"Usage: $0 {start|stop|restart|status}"  
exit 1  
esac  
