Tomcat有可能在运行过程中挂掉,可以写一个shell脚本检测服务器状态如果挂了就重新启动
安装:apt-get install cron (服务器环境下默认都会安装)
1、sudo crontab –e : 修改 crontab 文件. 如果文件不存在会自动创建。
脚本具体格式如下:
# daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command */5 * * * * bash /home/user/script/monitor.sh 设置每5分钟执行一次脚本2、sudo crontab –l : 显示 crontab 文件。
3、sudo crontab -r : 删除 crontab 文件。
4、sudo crontab -ir : 删除 crontab 文件前提醒用户。
6,cron文件语法:
分 小时 日 月 星期 命令 0-59 0-23 1-31 1-12 0-6 command (取值范围,0表示周日一般一行对应一个任务) “*”代表取值范围内的数字, “/”代表”每”, “-”代表从某个数字到某个数字, “,”分开几个离散的数字7,有的系统中是crond不是cron,视具体情况使用
service cron start //启动服务
service cron stop //关闭服务
service cron restart //重启服务
service cron reload //重新载入配置