1. 新建timeRestart.sh文件并赋执行权(chmod +x timeRestart.sh )
#! /bin/bash
count=`ps -ef | grep platform-1.0-SNAPSHOT.jar | grep -v "grep" | wc -l`
sec=7
nowtime=`date +"%Y-%m-%d %H:%M:%S"`
nowDate=`date +"%Y-%m-%d"`
for var in 1 2
do
if [ $count -gt 0 ]; then
echo sleep $sec second the $var time, the platform-1.0-SNAPSHOT.jar Thread is still alive
sleep $sec
else
nohup java -jar -Dspring.profiles.active=demo /root/platform-1.0-SNAPSHOT.jar &
echo $nowtime" start platform-1.0-SNAPSHOT.jar"
echo "ok! is success!"
echo ""
break
fi
done
2. 新增cron任务
crontab -e
输入保存
*/1 * * * * /root/timeRestart.sh >> /root/restart.log
3. 查询cron状态
service crond status