#!/bin/bash
#执行方法 start|stop
mulu=$(dirname $(readlink -f $0))
# 执行方法:-a start|stop
a='start'
# 执的版本号, 例如:-v 2.2.0
v=3.2
n=
d='prod'
#执行名字例如:-n ruoyi-gateway
# 'ruoyi-modules-job' 'ruoyi-visual-monitor'
# arr=('ruoyi-gateway' 'ruoyi-auth' 'ruoyi-modules-system' 'ruoyi-modules-job' 'ruoyi-modules-gen' 'ruoyi-visual-monitor' 'ruoyi-modules-file' 'beiyao-zt-erp')
arr=('yshop-app' 'yshop-admin' 'yshop-chat')
while getopts ":v:n:a:d:" opt
do
case $opt in
n)
n=$OPTARG
arr=($OPTARG)
echo "当前操作应用:$OPTARG"
;;
v)
v=$OPTARG
echo "版本号:$OPTARG"
;;
a)
a=$OPTARG
echo "操作方法:$OPTARG"
;;
d)
d=$OPTARG
echo "启动环境:$OPTARG"
;;
?)
echo "未知参数,-v 2.0.0 -n nginx -i start|stop -d prod"
exit 1;;
esac
done
if [ ! -n "$v" ]; then
echo "IS NULL"
else
for ((i=0; i<${#arr[@]};i++))
do
arr[$i]=${arr[i]}-$v;
echo ${arr[i]};
done
# echo "NOT NULL"
fi
function stopjar(){
PID=$(ps -ef | grep $1.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo $1 is already stopped
else
echo "stop $1.jar kill -9 $PID"
kill -9 $PID
fi
}
function startjar(){
stopjar $1
echo "start nohup java -Dfile.encoding=utf-8 -Duser.timezone=GMT+8 -Dspring.profiles.active=$d -jar -Xmx512M $mulu/$1.jar >$mulu/logs/$1.out 2>&1 &"
nohup java -Dfile.encoding=utf-8 -Duser.timezone=GMT+8 -Dspring.profiles.active=$d -jar -Xmx512M $mulu/$1.jar >$mulu/logs/$1.out 2>&1 &
}
function stop(){
length=${#arr}
# for 遍历
for item in ${arr[*]}
do
echo "stop" $item
stopjar $item
done
}
function start(){
length=${#arr}
echo "开始服务:$length"
# for 遍历
for item in ${arr[*]}
do
startjar $item
done
}
echo "$a $d"
$a
网友评论