进程监控脚本

#!/bin/sh
BASEPATH=/home/ServiceMonitoring
INSTALLPATH=/opt/opzoonface/ServiceMonitoring

chmod 755 -R ${INSTALLPATH}/*

runTomcat(){
  echo "tomcat is already installed!"
  #ps x | grep saas-tomcat | grep -v grep | grep -v sh
  countTomcat=`ps -ef|grep saas-tomcat|grep -v grep|awk '{print $2}'`
  if [ -n "$countTomcat" ]; then
    echo "saas-tomcat is running!"
  else
    echo "saas-tomcat is stoped! try to run it!"
    systemctl restart saas-tomcat.service
  fi
}
runNetty(){
  echo "netty is already installed!"
  #ps x | grep netty | grep -v grep | grep -v sh
   countNetty=`ps -ef|grep device-comm-api |grep -v grep|awk '{print $2}'`
  if [ -n "$countNetty" ]; then
    echo "netty is running!"
  else
    echo "netty is stoped! try to run it!"
      systemctl start netty.service
  fi
}
runRabbitMQ(){
  #ps x | grep rabbitmq | grep -v grep | grep -v sh
  countRabbitMQ=`ps -ef|grep rabbitmq_server|grep -v grep|awk '{print $2}'`
  if [ -n "$countRabbitMQ" ]; then
    echo "rabbitMQ is running!"
  else
    echo "rabbitMQ is stoped! try to run it!"
      systemctl restart rabbitmq-server
      #nohup rabbitmq-server start &
    # reboot netty
    nettyPid=`ps -ef|grep device-comm-api |grep -v grep|awk '{print $2}'`
    kill -9 nettyPid
    runNetty
  fi
}

runRedis(){
  countRedis=`ps -ef|grep redis-server|grep -v grep|awk '{print $2}'`
  if [ -n "$countRedis" ]; then
    echo "redis is running!"
  else
    echo "redis is stoped! try to run it!"
      systemctl restart redis.service
  fi
}
runMYSQL(){
  countMYSQL=`ps -ef|grep mysql|grep -v grep|awk '{print $2}'`
  if [ -n "$countMYSQL" ]; then
    echo "MYSQL is running!"
  else
    echo "MYSQL is stoped! try to run it!"
       service mysqld start
  fi
}
runFrpc(){
  countFRPC=`ps -ef|grep frpc|grep -v grep|awk '{print $2}'`
  if [ -n "$countFRPC" ]; then
    echo "FRPC is running!"
  else
    echo "FRPC is stoped! try to run it!"
    systemctl start frpc.service
  fi
}
runAlgorithm(){
  countAlgorithm=`ps -ef|grep algorithm-tomcat|grep -v grep|awk '{print $2}'`
  if [ -n "$countAlgorithm" ]; then
    echo "Algorithm-tomcat is running!"
  else
    echo "Algorithm-tomcat is stoped! try to run it!"
    /opt/opzoonface/algorithm-tomcat/bin/startup.sh
  fi
}

runPic(){
  countPic=`ps -ef|grep pic-tomcat|grep -v grep|awk '{print $2}'`
  if [ -n "$countPic" ]; then
    echo "pic-tomcat is running!"
  else
    echo "pic-tomcat is stoped! try to run it!"
    systemctl start pic-tomcat.service
  fi
}
runNginx(){
  countNginx=`ps -ef|grep 'openresty/nginx'|grep  -v grep|awk '{print $2}'`
  if [ -n "$countNginx" ]; then
    echo "openresty is running!"
  else
    echo "openresty is stoped! try to run it!"
    /opt/opzoonface/openresty/nginx/sbin/nginx -c /opt/opzoonface/openresty/nginx/conf/nginx.conf
  fi
}
runFaceApi(){
  countFaceApi=`ps -ef|grep 'face-api'|grep  -v grep|awk '{print $2}'`
  if [ -n "$countFaceApi" ]; then
    echo "FaceApi is running!"
  else
    echo "FaceApi is stoped! try to run it!"
    systemctl start  face-api.service
  fi
}
#main function
if [ -d ${INSTALLPATH} ]; then
  runTomcat
  runNetty
  runRabbitMQ
  runRedis
  runMYSQL
  runFrpc
  runPic
  runAlgorithm
  runNginx
  runFaceApi
fi

你可能感兴趣的:(进程监控脚本)