Monitor the java project under the linux system, if the project stops, it will automatically restart and save the log

 Here is the script:

#! /bin/bash
#
# service-restart      Automount system service in the specified direcotry.
#
# chkconfig: 2345 90 10
# description: 这个程序用来监控服务器服务软件,以程序挂掉后重启 Author is six  2020年12月1日15:40:45.
# ! /bin/sh
LOG_FILE="/opt/xie/my-project/errorLog/restart.log"
SERVICE_NAME="my-project"
cd /opt/six/my-project/
while true 
do
    project=`ps -ef|grep "my-project"|grep -v grep|wc -l`
    if [ $project -eq 0 ]
    then
        #echo "start tomcat..."
        echo `date +%Y-%m-%d` `date +%H:%M:%S`  $SERVICE_NAME >>$LOG_FILE
        nohup java -jar my-project.jar > nohup.out 2>&1 &
   # else 
        #echo "no start"
    fi
    sleep 60 #每60秒检查一轮
done

Script background startup command: nohup ./project.sh >/dev/null 2>&1 &

Command explanation: https://blog.csdn.net/chang_li/article/details/54138207

                  https://blog.csdn.net/My_SweetXue/article/details/110435431

----------------------------------------------------------------------------------------------------------------------------------------------

 

 

Guess you like

Origin blog.csdn.net/My_SweetXue/article/details/110432667