sh启动脚本 java jar包启动命令,防止new Date时区不准,乱码现象

启动命令(时区中国区):-Duser.timezone=GMT+8
编码类型:-Dfile.encoding=UTF-8
最大内存 -Xmx512M

java -jar -Dfile.encoding=UTF-8  -Duser.timezone=GMT+8  -Xmx512M /home/server/ruoyi-modules-job.jar

start.sh

#!/bin/bash
#执行方法 start|stop

mulu=$(dirname $(readlink -f $0))
# 执行方法:-a start|stop
a='start'
# 执的版本号, 例如:-v 2.2.0
v=
n=
#执行名字例如:-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=('ruoyi-gateway' 'beiyao-modules-tiancheng' 'beiyao-modules-system')
while getopts ":v:n:a:" opt
do
    case $opt in
        n)
        n=$OPTARG
        arr=($OPTARG)
        echo "当前操作应用:$OPTARG"
        ;;
        v)
        v=$OPTARG
        echo "版本号:$OPTARG"
        ;;
        a)
        a=$OPTARG
        echo "操作方法:$OPTARG"
        ;;
        ?)
        echo "未知参数,-v 2.0.0 -n nginx -i start|stop"
        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" $1
    nohup java -Dfile.encoding=utf-8 -Duser.timezone=GMT+8 -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"
$a

你可能感兴趣的:(sh启动脚本 java jar包启动命令,防止new Date时区不准,乱码现象)