#!/bin/bash
### BEGIN INIT INFO
# Provides:             sdsvrd
# Required-Start:       
# Required-Stop:        
# Default-Start:        2 3 4 5
# Default-Stop:         
# Short-Description:    safedog server
### END INIT INFO

function checkprocess()
{
	checknum=$1

	cur_num=`ps -ef|grep sdmonitor|grep -v grep|grep -v sdmonitor.log|wc -l`
	while [ "$cur_num" != "$checknum" ]
	do
		sleep 0.5	
		cur_num=`ps -ef|grep sdmonitor|grep -v grep|grep -v sdmonitor.log|wc -l`
		#echo "cur_num:"$cur_num
	done
}


############quit sdmonitor############
sdmonitor -QUIT   1>/dev/null 2>&1
checkprocess  0
sleep 1
killall sdmonitor 2>/dev/null

############start sdmonitor############
export LC_ALL="C"
sdmonitor
checkprocess  1
sleep 2

############start sdcc############
sdmonitor -r sdcc   1>/dev/null 2>&1
sleep 0.5

############start sdsvrd############
sdmonitor -r sdsvrd   1>/dev/null 2>&1
sleep 0.5

############start udcenter############
sdmonitor -r udcenter   1>/dev/null 2>&1
sleep 0.5

############start sdacm############
if [[ -f /etc/apachesd.conf || -f /etc/nginxsd.conf ]]; 
then
	sdmonitor -s sdacm 1>/dev/null 2>&1
fi
