1.終止jar包進(jìn)程
#!/bin/bash
SERVER_NAME="base-server"
JAR_NAME=${SERVER_NAME}.jar
#查找進(jìn)程
PID=$(ps -ef | grep ${JAR_NAME}= | grep -v grep | awk '{print $2}')
if [ ! $PID ]; then
echo "process ${SERVER_NAME} not exit"
exit
else
echo "process id: $PID"
fi
#殺死進(jìn)程
kill -9 ${PID}
#判斷上一次命令執(zhí)行的成功或者失敗的狀態(tài)亮蒋。如果成功就是0塘幅,失敗為1.
if [ $? -eq 0 ]; then
echo "kill ${SERVER_NAME} success"
else
echo "kill ${SERVER_NAME} fail"
fi
2.開啟jar包進(jìn)程
#!/bin/bash
#-Xms: 設(shè)置初始化堆內(nèi)存大形恪;
#-Xmx: 設(shè)置最大可分配堆內(nèi)存大小
#MetaspaceSize:元空間默認(rèn)大小
#MaxMetaspaceSize:元空間最大大小
#JVM參數(shù)配置
JVM_OPTS="-Xms128m -XX:MetaspaceSize=128M -Xmx128m -XX:MaxMetaspaceSize=512M -Dfile.encoding=utf-8"
LOG_HOME="/home/logs/"
#jar包名稱
SERVER_NAME="base-server"
#當(dāng)前日期
TODAY=$(date -d "now" +"%Y-%m-%d")
#日志文件路徑
LOG_PATH="${LOG_HOME}${SERVER_NAME}/${TODAY}/com.northmeter-deb.log"
#配置文件環(huán)境
ACTIVE="test"
#腳本絕對路徑
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
#jar包絕對路徑
JAR_PATH="${SCRIPT_DIR}/${SERVER_NAME}.jar"
echo start ${SERVER_NAME} ..
#啟動jar包 + 指定配置文件環(huán)境 +讀取啟動日志+后臺啟動
nohup java ${JVM_OPTS} -jar ${JAR_PATH} --spring.profiles.active=${ACTIVE}>${LOG_PATH} 2>&1 & tail -200f ${LOG_PATH}
echo 'start successful'
sh腳本文件授權(quán)‘
chmod 777 filename