#!/bin/bash
echo "This user's path is:"$HOME
while true
do
echo ""
echo "System Date is "$(date +%Y-%m-%d\ %H:%M:%S)
serviceNum=$(ps aux|grep business|grep -v grep|awk '{print $2}'|wc -l)
echo "this service number is "$serviceNum
echo "these servicePids are..."$(ps aux|grep business|grep -v grep|awk '{print $2}')
num=$(tail -n 100 $HOME/business/stdout.log|grep 'OutOfMemory'|wc -l)
echo "OutOfMemory number is "$num
if [[ $num -gt 0 ]]
then
echo "This service have OutOfMemoryError..."
ps -ef|grep business|grep -v grep|awk '{print $2}'|xargs kill -9
echo "kill this service..."
nohup java -jar business-layer-starter-1.0.0-SNAPSHOT.jar --debug=false>stdout.log 2>&1 &
echo "startup this service..."
elif [[ $serviceNum -eq 0 ]]
then
echo "This service is stoped..."
nohup java -jar business-layer-starter-1.0.0-SNAPSHOT.jar --debug=false>stdout.log 2>&1 &
echo "startup this service..."
else
echo "this service not have OutOfMemoryError and this service starting"
fi
sleep 120 #sleep time is 's';
done