Background requirements, on the speed measurement server, pull the source code, compile the front and back ends, and finally redeploy
So there is the following script to avoid constant typing commands,
Here we use the RuoYi front-end separation project as an example
Here I am using the soft link method, to achieve, please see for details
logs
manage.sh -> /home/rock/ruoyi/RuoYi-Vue/manage.sh
nohup.out
ruoyi-admin.jar -> /home/rock/Desktop/RuoYi-Vue/ruoyi-admin/target/ruoyi-admin.jar
RuoYi-Vue -> /home/rock/Desktop/RuoYi-Vue
uploadPath
screenplay
#!/bin/bash
# 这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=ruoyi-admin.jar
# 前端目录
FORE=ruoyi-ui
# 源码目录
DIR=RuoYi-Vue
# JVM参数
JVM_OPTS="-Xmx1024m"
# 进入当前Shell程序的目录
cd `dirname $0`
# 使用说明,用来提示输入参数
usage() {
status
echo "用法: sh 执行脚本.sh [start|stop|restart|status|log|pull|build|fore|after]"
exit 1
}
#检查程序是否在运行
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
#启动方法
start(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} 正在运行. pid=${pid} ."
else
nohup java $JVM_OPTS -jar $APP_NAME &
echo "${APP_NAME} 启动成功"
echo "查看日志请输入:tail -f nohup.out"
fi
}
#停止方法
stop(){
is_exist
if [ $? -eq "0" ]; then
# 优雅停服
curl -X POST http://127.0.0.1:8080/actuator/shutdown
# kill -9 $pid
echo "${APP_NAME} 已经停止"
else
echo "${APP_NAME} 未运行"
fi
}
#拉取源码
pull(){
cd $DIR
git pull
cd ..
echo "项目拉取完成"
}
#编译整个项目
build(){
stop
pull
after
fore
echo "项目编译完成"
}
#编译前端
fore(){
cd $DIR
cd $FORE
sh build.sh
cd ../..
echo "前端编译完成"
}
#编译后端
after(){
stop
cd $DIR
sh build.sh
cd ..
echo "后端编译完成"
}
#输出运行状态
status(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} 正在运行. PID : ${pid}"
else
echo "${APP_NAME} 未运行."
fi
}
#重启
restart(){
stop
start
}
#看日志
log(){
tail -f nohup.out
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
"log")
log
;;
"pull")
pull
;;
"build")
build
;;
"fore")
fore
;;
"after")
after
;;
*)
usage
;;
esac