#!/bin/sh
# Author:tang
# Date:2017-09-01
ProcessName=webcrawler
InstanceCount=6
RuntimeLog='runtime.log'
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib
ulimit -c unlimited
echo -n `date +'%Y-%m-%d %H:%M:%S'`
echo "----Current directory is " $PWD
# 检查$ProcessName实例是否已经存在
while [ 1 ] ; do
#$PROCESS_NUM获取指定进程名的数目
PROCESS_NUM=`ps -ef | grep "$ProcessName" | grep -v "grep" | wc -l`
if [ $PROCESS_NUM -lt $InstanceCount ];
then
StopCount=`expr $InstanceCount - $PROCESS_NUM `
echo -n `date +'%Y-%m-%d %H:%M:%S'`
echo "----$ProcessName service [total $StopCount] was not started."
echo -n `date +'%Y-%m-%d %H:%M:%S'`
echo "----Starting $ProcessName service[total $StopCount] ."
for(( i = 0 ; i< $StopCount ; i++ ))
do
nohup $PWD/$ProcessName >>/dev/null 2>&1 &
done
fi
sleep 2
done