#! /bin/sh
#
# See contrib/init.resin for /etc/rc.d/init.d startup script
#
# resin.sh can be called like apachectl
#
# resin.sh -- execs resin in the foreground
# resin.sh start -- starts resin in the background
# resin.sh stop -- stops resin
# resin.sh restart -- restarts resin
#
# resin.sh will return a status code if the wrapper detects an error, but
# some errors, like bind exceptions or Java errors, are not detected.
#
# To install, you'll need to configure JAVA_HOME and RESIN_HOME and
# copy contrib/init.resin to /etc/rc.d/init.d/resin. Then
# use "unix# /sbin/chkconfig resin on"
PCK_TAG=pcheck
export=PCK_TAG
#JAVA_HOME
JAVA_HOME=/usr/local/jdk1.6.0_29
export JAVA_HOME
#本脚本的绝对路径
EXEC_START="/usr/local/sns/snsconnector.sh"
#日志输入路径
WATCH_LOG="/usr/local/sns/watchdog.log"
export WATCH_LOG
#执行脚本
RESIN="bin/httpd.sh"
#执行多个resin的多路径
EXEC="/usr/local/sns/snsapi/resin3 /usr/local/sns/snsapi2/resin3"
array=($EXEC)
length=${#array[@]}
echo $length
for ((i=0; i<$length; i++))
do
echo ${array[$i]}
done
#####################################################
# Find a PID for the pid file
#####################################################
for ((i=0; i<$length; i++))
do
RESIN_HOME=${array[$i]}
SNS_PIDS="$SNS_PIDS $RESIN_HOME/snsconnector.pid "
done
pids=($SNS_PIDS)
size=${#pids[@]}
echo $size
for ((i=0; i<$size; i++))
do
echo ......${pids[$i]}
done
#
SNS_TAG=snstag
if test -n "${JAVA_HOME}"; then
if test -z "${JAVA_EXE}"; then
JAVA_EXE=$JAVA_HOME/bin/java
fi
fi
#
# trace script and simlinks to find the wrapper
#
if test -z "${RESIN_HOME}"; then
script=`/bin/ls -l $0 | awk '{ print $NF; }'`
while test -h "$script"
do
script=`/bin/ls -l $script | awk '{ print $NF; }'`
done
bin=`dirname $script`
RESIN_HOME="$bin/.."
fi
running()
{
[ -f $1 ] || return 1
PID=$(cat $1)
echo ==========$PID==========
ps -p $PID >/dev/null 2>/dev/null || return 1
return 0
}
zombiling()
{
PID=$(cat $1)
echo "zombiling $PID" >>$WATCH_LOG
IMZOMBIE=`ps -el |grep $PID|awk '{print $2}'` >/dev/null 2>/dev/null
imarray=($IMZOMBIE)
echo "SNSConnector process current run status is: ${imarray[0]}" >>$WATCH_LOG
echo "SNSConnector process current run status is: $IMZOMBIE"
echo "`date '+%Y-%m-%d %T'` [INFO] SNSConnector process current run status is: $IMZOMBIE" >>$WATCH_LOG
if [ ! -z `echo ${imarray[0]}|grep '^[TZ]'` ]
then
echo "SNSConnector process is zombied. now restart the service."
echo "`date '+%Y-%m-%d %T'` [WARN] SNSConnector process is zombied. now restart the service." >>$WATCH_LOG
return 0
fi
return 1
}
usage()
{
echo "Usage: $0 {start|stop|status} [ CONFIGS ... ] "
exit 1
}
[ $# -gt 0 ] || usage
ACTION=$1
MAINTE_CHECK=$2
ZOMBIE_CHECK=$3
#####################################################
# Get current script belongs to User and Group.
#####################################################
[ -z ${SCRIPT_NAME} ] && SCRIPT_NAME=httpd.sh
if [ -f ${RESIN_HOME}/bin/${SCRIPT_NAME} ]
then
CURRENT_GROUP="$(echo `ls -l ${RESIN_HOME}/bin/${SCRIPT_NAME}` | awk '{print $4}')";
CURRENT_USER="$(echo `ls -l ${RESIN_HOME}/bin/${SCRIPT_NAME}` | awk '{print $3}')";
else
echo "`date '+%Y-%m-%d %T'` ERROR: Current start service script is:${RESIN_HOME}/bin/${SCRIPT_NAME}" >>$WATCH_LOG
echo "`date '+%Y-%m-%d %T'` ERROR: The SNS start file is not exist."
fi
setCrontab()
{
echo "setCrontab...";
crontab_tmp=$(mktemp -p "${RESIN_HOME}/bin/")