服务进程自启动脚本,实现每分钟检查服务运行状态

来源:互联网 发布:ik hr人力资源软件 编辑:程序博客网 时间:2024/05/18 00:05

由于程序真是环境不是由自己运维的,真是负责运维的人员并不了解软件,所以增加一份自启动脚本

脚本原理:利用linux系统的crontab定时任务,每一分钟检查一次系统进程是否存在,若不存在则调用启动命令并记录日志



#!/bin/sh#启动日志存放路径startPath=/data/start.log#检查启动日志是否存在if [ ! -f $startPath ];thentouch $startPathchown bfc:bfc $startPathcurDate=`date +%s`curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`echo $curTime: logstart >> $startPathelsechown bfc:bfc $startPathfi#检查mysql是否启动pid=`ps -ef|grep mysql | grep -v grep |awk '{print $2}'`if [ "$pid" == "" ];thenservice mysql restartsleep 5pid=`ps -ef|grep mysql | grep  -v grep | awk '{print $2}'`if [ "$pid" = "" ];thencurDate=`date +%s`curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`echo "$curTime: mysql start faild!!!" >> $startPathelse curDate=`date +%s`                curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`echo "$curTime: mysql start success." >> $startPathfielse curDate=`date +%s`        curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`echo "$curTime: mysql process already exists." >> $startPathfi#启动espid=`jps -l | grep org.elasticsearch.bootstrap.Elasticsearch | awk '{print $1}'`if [ "$pid" == "" ];thensu - bfc <<EOF/data/elasticsearch2017-04-11/elasticsearch-2.4.3/bin/elasticsearch -d;exit;EOFsleep 5pid=`jps -l | grep org.elasticsearch.bootstrap.Elasticsearch | awk '{print $1}'`if [ "$pid" == "" ];thencurDate=`date +%s`                curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`                echo "$curTime: elasticsearch start faild!!!" >> $startPathelsecurDate=`date +%s`                curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`                echo "$curTime: elasticsearch start success." >> $startPathfielsecurDate=`date +%s`        curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`        echo "$curTime: elasticsearch process already exists." >> $startPathfi#启动主服务pid=`ps -ef | grep tomcat |grep -v grep| awk '{print $2}'`if [ "$pid" == "" ];thenchmod +x /data/apache-tomcat-8.0.32/bin/*.sh/data/apache-tomcat-8.0.32/bin/startup.shsleep 30echo "sleep 30"pid=`ps -ef | grep tomcat |grep -v grep| awk '{print $2}'`if [ "$pid" == "" ];thencurDate=`date +%s`                curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`                echo "$curTime: BFC start faild!!!" >> $startPathelsecurDate=`date +%s`                curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`                echo "$curTime: BFC start success." >> $startPathfielsecurDate=`date +%s`       curTime=`date -d @$curDate "+%Y-%m-%d %H:%M:%S"`        echo "$curTime: BFC has started." >> $startPathfi

阅读全文
0 0
原创粉丝点击