脚本编写
#!/bin/sh
source /root/.bashrc // 引入Java系统环境变量
RESOURCE_NAME=uu/gc_8071_8072/uu_gamecollect-2.1.2-SNAPSHOT.jar
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'app is running '
else
rm -f tpid
nohup java -jar /$RESOURCE_NAME --spring.profiles.active=test &
echo $! > tpid
echo Start Success!
fi
crontab -e 编写启动脚本
*/1 * * * * cd /uu/gc_8071_8072 && ./uu_port_start.sh >> /uu/gc_8071_8072/crontab.log 2>&1 &
每分钟执行一次脚本,cd /uu/gc_8071_8072 脚本所在目录,./uu_port_start.sh为脚本;/uu/gc_8071_8072/crontab.log 为log输出目录。