stand-alone chmod -R 777 xx.sh vim xx.sh :set ff=unix
Start & Stop
#!/bin/bash
# PROJECT_PATH=/doc/program/smart/soul-admin.jar
# read -p ":" PROJECT_PATH
# echo "你输入的数是:$PROJECT_PATH"
echo 如果下面的参数都在文件中写死了那就直接回车跳过设置
read -p "请输入项目路径(+jar名.jar):" PROJECT_PATH
read -p "请设置端口:" PROJECT_PORT
read -p "请设置配置文件:" PROJECT_PROPERTIES
# 设置环境参数
JAVA_OPTS=" -Xms512m "
# -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
JAVA_OPTS="${JAVA_OPTS} -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC "
JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
# 设置默认值
if [ ! $PROJECT_PATH ]; then
PROJECT_PATH="test.jar"
fi
if [ ! $PROJECT_PORT ]; then
SERVER_PORT=" --server.port=1234"
else
SERVER_PORT=" --server.port=${PROJECT_PORT}"
fi
if [ ! $PROJECT_PROPERTIES ]; then
SERVER_PROPERTIES="--spring.profiles.active=prod"
else
SERVER_PROPERTIES="--spring.profiles.active=${PROJECT_PROPERTIES}"
fi
# shutdown
pid=`ps -ef|grep $PROJECT_PATH | grep -v grep | awk '{print $2}'`
kill -9 $pid
echo "$pid进程终止成功"
sleep 1
# startUp
sleep 2
# 判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
if test -e $PROJECT_PATH
then
echo '文件存在,开始启动此程序...'
# 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
echo "nohup java -jar $JAVA_OPTS "$PROJECT_PATH" $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &"
nohup java -jar $JAVA_OPTS $PROJECT_PATH $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &
echo "$PROJECT_PATH 启动成功..."
else
echo "$PROJECT_PATH 文件不存在,请检查。"
fi
Start
#!/bin/bash
# PROJECT_PATH=/doc/program/smart/soul-admin.jar
# read -p ":" PROJECT_PATH
# echo "你输入的数是:$PROJECT_PATH"
echo 如果下面的参数都在文件中写死了那就直接回车跳过设置
read -p "请输入项目路径(+jar名.jar):" PROJECT_PATH
read -p "请设置端口:" PROJECT_PORT
read -p "请设置配置文件:" PROJECT_PROPERTIES
# 设置环境参数
JAVA_OPTS=" -Xms512m "
# -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
JAVA_OPTS="${JAVA_OPTS} -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC "
JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
# 设置默认值
if [ ! $PROJECT_PATH ]; then
PROJECT_PATH="test.jar"
fi
if [ ! $PROJECT_PORT ]; then
SERVER_PORT=" --server.port=1234"
else
SERVER_PORT=" --server.port=${PROJECT_PORT}"
fi
if [ ! $PROJECT_PROPERTIES ]; then
SERVER_PROPERTIES="--spring.profiles.active=prod"
else
SERVER_PROPERTIES="--spring.profiles.active=${PROJECT_PROPERTIES}"
fi
# startUp
sleep 2
# 判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
if test -e $PROJECT_PATH
then
echo '文件存在,开始启动此程序...'
# 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
echo "nohup java -jar $JAVA_OPTS "$PROJECT_PATH" $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &"
nohup java -jar $JAVA_OPTS $PROJECT_PATH $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &
echo "$PROJECT_PATH 启动成功..."
else
echo "$PROJECT_PATH 文件不存在,请检查。"
fi
Stop
#!/bin/bash
# PROJECT_PATH=/doc/program/smart/soul-admin.jar
# read -p ":" PROJECT_PATH
# echo "你输入的数是:$PROJECT_PATH"
echo jps -l 查看
read -p "请输入项目路径(+jar名.jar):" PROJECT_PATH
# 设置默认值
if [ ! $PROJECT_PATH ]; then
PROJECT_PATH="test.jar"
fi
# shutdown
pid=`ps -ef|grep $PROJECT_PATH | grep -v grep | awk '{print $2}'`
kill -9 $pid
echo "$pid进程终止成功"
sleep 1