2 Star 4 Fork 1

uestc-fzk/blog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
service.sh 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
uestc-fzk 提交于 2025-03-10 23:45 +08:00 . auto
#!/bin/bash
jarfile="target/blog-1.3.0-GA.jar"
app_args="--spring.profiles.active=product --server.port=9090"
# jvm选项参数
jvm_options="-Xmx2g -Xms128m -Xss512k -XX:+UseG1GC -XX:MaxGCPauseMillis=10 -XX:+HeapDumpOnOutOfMemoryError -XX:+HeapDumpBeforeFullGC -XX:HeapDumpPath=jvm/heap.dump -Xlog:gc*=debug,gc+task*=info:file=jvm/gc%t.log:utctime,level,tags:filecount=50,filesize=100M"
# jvm日志输出目录
jvmLogDir="jvm"
if [ ! -e ${jvmLogDir} ]
then
mkdir -m 664 ${jvmLogDir}
fi
pid=`ps -ef | grep "${jarfile}" | grep -v grep| awk '{print $2}'` # 现存服务的pid
function start_func(){
echo "即将启动服务: ${jarfile}"
if [ -z "${pid}" ] # 检查字符串是否为空
then
echo "nohup java ${jvm_options} -jar ${jarfile} ${app_args} &"
nohup java ${jvm_options} -jar ${jarfile} ${app_args} &
echo "服务启动成功: ${jarfile}"
else
echo "服务早已启动: pid: ${pid}"
fi
ps -ef | grep ${jarfile} | grep -v "grep"
}
function stop_func(){
echo "即将关闭服务: ${jarfile}"
if [ ! -z "${pid}" ] # 检查字符串是否为空
then
echo "关闭服务: ${jarfile}, pid: ${pid}"
kill ${pid}
echo "成功关闭, pid: ${pid}"
pid=""
else
echo "服务不存在: ${jarfile}"
fi
}
if [ $1 = "start" ]
then
start_func
elif [ $1 = "stop" ]
then
stop_func
elif [ $1 = "restart" ]
then
echo "即将重启服务: ${jarfile}"
stop_func
sleep 5s
start_func
else
echo "非法参数"
exit 1
fi # 这个fi必须得有
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/uestc-fzk/blog.git
git@gitee.com:uestc-fzk/blog.git
uestc-fzk
blog
blog
c5eb4bd889cf6ba2fc722f08cd9e6cfac6e58496

搜索帮助