写一个monitor.sh脚本用于判断tomcat进程是否存在,若不存在则启动tomcat
脚本链接https://download.youkuaiyun.com/download/qq_41959871/13722321
查看定时任务状态systemctl status crond
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
查看已有的定时任务
crontab -l
编辑定时任务
crontab -e
根据脚本所在位置写入:
*/5 * * * * /develop/montior/monitor.sh
每五分钟执行一次
然后重启定时服务
/sbin/service crond restart
检测到没有启动时的日志输出
正常启动后的定时任务中的日志输出
部署过程遇到的坑:
手动执行脚本,无任何异常,tomcat能被脚本正常启动但定时器执行的脚本过程
tomcat启动失败报错:
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
说没有java的环境
编辑/tomcat/bin下catalina.sh
export JAVA_HOME=/software/jdk1.8
export JRE_HOME=/software/jdk1.8/jre
指定linux环境jdk目录,脚本可以启动tomcat,应该是定时任务没有办法获取到tomcat默认配置的JRE_HOME导致的