天天看点

Java 进程保活方式

目录

第一种方式:Java Service Wrapper

第二种:编写Shell定时任务脚本

第三种方式:使用Monit搭建监控系统

第四种方式:用Supervisord管理进程

第一种方式:Java Service Wrapper

使用社区版本就可以了

下载地址:https://wrapper.tanukisoftware.com/doc/english/download.jsp

详细使用见:https://www.cnblogs.com/happyday56/p/4204090.html

第二种:编写Shell定时任务脚本

也就是shell中的crontab定时任务,详细使用见:https://www.cnblogs.com/huxinga/p/7779433.html

Shell脚本样例:

#!/bin/sh
export JAVA_HOME=/usr/local/jdk1.8.0_161
export JRE_HOME=$JAVA_HOME/jre

## service name
SERVICE_NAME=thingModel.service-0.0.1-SNAPSHOT
SERVICE_JAR=thingModel.service-0.0.1-SNAPSHOT.jar
SERVICE_DIR=/home/thingModel/dubbo
JAR_NAME=$SERVICE_NAME\.jar
PID=$SERVICE_NAME\.pid    

        ## thinkiot.lenovo.service.jar
        P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "=== $SERVICE_NAME process not exists or stop success"
                  nohup $JRE_HOME/bin/java/bin/java -jar  -Xmx512m -Xms512m $SERVICE_JAR &
        else
            echo "=== $SERVICE_NAME process pid is:$P_ID"
        fi       
exit 0
           

第三种方式:使用Monit搭建监控系统

https://blog.csdn.net/zzti_erlie/article/details/80367997

第四种方式:用Supervisord管理进程

https://blog.csdn.net/jek123456/article/details/76985154