java 通用启动jar包脚本 和关闭脚本

2023-12-28 13:09:16
echo "" > nohup.log
sh stop.sh
cd `dirname $0`
BIN_DIR=`pwd`
for i in classes/lib/*.jar;?
do CLASSPATH=$i:"$CLASSPATH";?
done

nohup /usr/java/jdk-11.0.15.1/bin/java ?-Dfile.encoding=UTF-8 -classpath $CLASSPATH:"$BIN_DIR/classes" ?com.kion.fms.vehicledmservice.VehicleDMServiceApplication >> $BIN_DIR/nohup.log 2>&1 &

##nohup /usr/java/jdk-11.0.15.1/bin/java -jar fmsvehicledmservice-1.0.0-SNAPSHOT.jar >> $BIN_DIR/nohup.log 2>&1 &
echo $! > $BIN_DIR/savePid.txt
cat $BIN_DIR/savePid.txt
tail -f $BIN_DIR/nohup.log

以上脚本先启动了stop.sh 然后启动jar包或者 class 然后将启动pid写入 savePid.txt中

以下是stop.sh

#!/bin/bash
PID=`cat savePid.txt` 
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
LOGS_DIR=$DEPLOY_DIR
if [ ! -d $LOGS_DIR ]; then
    mkdir $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/stdout.log

#PID=`ps -ef | grep -v grep | grep "$DEPLOY_DIR" | awk '{print $2}'` 

echo "PID: $PID"
if [ -z "$PID" ]; then
    echo "ERROR: The  server does not started!"
    exit 1
fi

echo -e "Stopping the  server ...\c"
kill $PID > $STDOUT_FILE 2>&1

COUNT=0
while [ $COUNT -lt 1 ]; do    
    echo -e ".\c"
    sleep 1
    COUNT=1
    PID_EXIST=`ps -f -p $PID | grep java`
    if [ -n "$PID_EXIST" ]; then
        COUNT=0
    fi
done

echo "stopped"
echo "PID: $PID"
 

可安装需求修改文件名称 和依赖目录名称? ?以上均为linux下运行脚本

文章来源:https://blog.csdn.net/qq_28130847/article/details/135263676
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。