服务进程自启动脚本,实现每分钟检查服务运行状态
2017-12-04 10:01
483 查看
由于程序真是环境不是由自己运维的,真是负责运维的人员并不了解软件,所以增加一份自启动脚本
脚本原理:利用linux系统的crontab定时任务,每一分钟检查一次系统进程是否存在,若不存在则调用启动命令并记录日志
脚本原理:利用linux系统的crontab定时任务,每一分钟检查一次系统进程是否存在,若不存在则调用启动命令并记录日志
#!/bin/sh #启动日志存放路径 startPath=/data/start.log #检查启动日志是否存在 if [ ! -f $startPath ];then touch $startPath chown bfc:bfc $startPath curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo $curTime: logstart >> $startPath else chown bfc:bfc $startPath fi #检查mysql是否启动 pid=`ps -ef|grep mysql | grep -v grep |awk '{print $2}'` if [ "$pid" == "" ];then service mysql restart sleep 5 pid=`ps -ef|grep mysql | grep -v grep | awk '{print $2}'` if [ "$pid" = "" ];then curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: mysql start faild!!!" >> $startPath else curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: mysql start success." >> $startPath fi else curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: mysql process already exists." >> $startPath fi #启动es pid=`jps -l | grep org.elasticsearch.bootstrap.Elasticsearch | awk '{print $1}'` if [ "$pid" == "" ];then su - bfc <<EOF /data/elasticsearch2017-04-11/elasticsearch-2.4.3/bin/elasticsearch -d; exit; EOF sleep 5 pid=`jps -l | grep org.elasticsearch.bootstrap.Elasticsearch | awk '{print $1}'` if [ "$pid" == "" ];then curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: elasticsearch start faild!!!" >> $startPath else curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: elasticsearch start success." >> $startPath fi else curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: elasticsearch process already exists." >> $startPath fi #启动主服务 pid=`ps -ef | grep tomcat |grep -v grep| awk '{print $2}'` if [ "$pid" == "" ];then chmod +x /data/apache-tomcat-8.0.32/bin/*.sh /data/apache-tomcat-8.0.32/bin/startup.sh sleep 30 echo "sleep 30" pid=`ps -ef | grep tomcat |grep -v grep| awk '{print $2}'` if [ "$pid" == "" ];then curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: BFC start faild!!!" >> $startPath else curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: BFC start success." >> $startPath fi else curDate=`date +%s` curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"` echo "$curTime: BFC has started." >> $startPath fi
相关文章推荐
- Shell脚本实现监视指定进程的运行状态
- Shell脚本实现监视指定进程的运行状态
- 监控进程(二进制程序)运行状态的C语言实现与脚本实现
- Shell脚本实现检查服务器安全状态(用户、登录IP、防火墙检查)
- shell mysql服务状态检查脚本示例
- 基于lvs的DR模型搭建高可用的web服务,并部署wordpress,(附有脚本实现健康状态检测的代码) 推荐
- windows下通过bat脚本和计划任务实现设置某一服务的守护进程
- 检查邮件服务器的postfix-pop3-mysql服务状态的脚本
- shell脚本监控tomcat服务运行状态,服务关闭后进行重启
- shell脚本实现某一进程是否运行结束的监控
- 基于SignalR实现B/S系统对windows服务运行状态的监测
- Shell脚本实现监控iptables运行状态
- shell脚本实现多进程运行的方法示例
- 查看nova服务进程的运行时状态信息
- shell脚本检查Tomcat运行状态
- 基于SignalR实现B/S系统对windows服务运行状态的监测
- LVS服务脚本及后端服务健康状态检查
- 实现同一个脚本多次运行,系统中只有一个进程
- Shell脚本实现检测进程是否正在运行
- 检查nginx后端real server脚本,实现发现宕机剔除,恢复服务自动加入功能