1.终止jar包进程
#!/bin/bash
SERVER_NAME="base-server"
JAR_NAME=${SERVER_NAME}.jar
#查找进程
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
#杀死进程
kill -9 ${PID}
#判断上一次命令执行的成功或者失败的状态。如果成功就是0,失败为1.
if [ $? -eq 0 ]; then
echo "kill ${SERVER_NAME} success"
else
echo "kill ${SERVER_NAME} fail"
fi
2.开启jar包进程
#!/bin/bash
#-Xms: 设置初始化堆内存大小;
#-Xmx: 设置最大可分配堆内存大小
#MetaspaceSize:元空间默认大小
#MaxMetaspaceSize:元空间最大大小
#JVM参数配置
JVM_OPTS="-Xms128m -XX:MetaspaceSize=128M -Xmx128m -XX:MaxMetaspaceSize=512M -Dfile.encoding=utf-8"
LOG_HOME="/home/logs/"
#jar包名称
SERVER_NAME="base-server"
#当前日期
TODAY=$(date -d "now" +"%Y-%m-%d")
#日志文件路径
LOG_PATH="${LOG_HOME}${SERVER_NAME}/${TODAY}/com.northmeter-deb.log"
#配置文件环境
ACTIVE="test"
#脚本绝对路径
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
#jar包绝对路径
JAR_PATH="${SCRIPT_DIR}/${SERVER_NAME}.jar"
echo start ${SERVER_NAME} ..
#启动jar包 + 指定配置文件环境 +读取启动日志+后台启动
nohup java ${JVM_OPTS} -jar ${JAR_PATH} --spring.profiles.active=${ACTIVE}>${LOG_PATH} 2>&1 & tail -200f ${LOG_PATH}
echo 'start successful'
sh脚本文件授权‘
chmod 777 filename
网友评论