1、Java项目重启脚本
#!/bin/bash
# 定义一个函数来结束进程和启动新进程
function restart(){
JAR_NAME=$1 # jar包
LOG_NAME=$2 # 日志
JVM_ARGS=$3 # jvm 参数
PID=$(ps -ef | grep java | grep ${JAR_NAME} | awk '{ print $2 }')
if [[ ! -z "$PID" ]]; then
echo "Killing old process [${JAR_NAME}] with pid ${PID}"
kill -9 $PID
fi
echo "Starting new process [${JAR_NAME}]"
nohup java ${JVM_ARGS} -jar /home/seres-wms/${JAR_NAME}.jar --spring.profiles.active=dev > /home/seres-wms/${LOG_NAME}.log 2>&1 &
}
# 现在我们使用上面的函数来管理每个Jar文件
restart "seres-gateway" "seres-gateway" "-Xmn1000m -Xms1500m -Xmx1500m -XX:SurvivorRatio=8"
restart "seres-module-core-biz" "seres-core" "-Xmn1500m -Xms2000m -Xmx2000m -XX:SurvivorRatio=10"
restart "seres-module-system-biz" "seres-system" "-Xmn1000m -Xms1500m -Xmx1500m -XX:SurvivorRatio=8"
目录结构如下:其中log文件是自动生成