#!/bin/bash
export JAVA_HOME=/usr/local/jdk1.8.0_181 >/dev/null
export PATH=$JAVA_HOME/bin:$PATH >/dev/null
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar >/dev/null
#这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=yimohca-1.0.0.jar
APP_DIR=/opt/prd_yimohca
NEW_DIR=/opt/new_version/new_yimohca
BAK_DIR=/opt/prd_yimohca/bak_yimohca/`date +%Y-%m-%d-%H:%M`
#备份
backup(){
mkdir -p $BAK_DIR
cp $APP_DIR/$APP_NAME $BAK_DIR/
rm -rf $APP_DIR/$APP_NAME
mv $NEW_DIR/$APP_NAME $APP_DIR/
}
#启动方法
start(){
rm -f tpid
cd $APP_DIR/
#> nohup.out
nohup java -Xms256m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m -jar $APP_NAME --spring.config.location=./application-prd.properties &
echo $! > tpid
echo 'Start Success!'
sleep 1
}
#停止方法
stop(){
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi
}
#重启
restart(){
stop
start
}
#新包发布重启
new_restart(){
stop
backup
start
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"backup")
backup
;;
"start")
start
;;
"stop")
stop
;;
"new_restart")
new_restart
;;
"restart")
restart
;;
*)
echo "usage: [ start | stop | restart | new_restart]"
;;
esac
springboot 以架包运行写好的.sh代码
最新推荐文章于 2021-11-28 13:59:30 发布