Linux怎么启动和停止SpringBoot jar程序
作者:WeekendFlower
时间:2023-06-02
来源:互联网
浏览:0
具体代码如下所示:#!/bin/bashcd`dirname$0`cur_shell_dir=`pwd`cur_shell_name=`basename${bash_source}`#修改这里jar包名即可jar_name="xxxxxxxxxxxx.jar"jar_path=$cur_shell_dir/$jar_name#java_mem_opts="-server-xms1024m-xmx1024m-xx:permsize=128m"java_mem_opts=""#spring_profiles_
具体代码如下所示:
#!/bin/bash
cd `dirname $0`
cur_shell_dir=`pwd`
cur_shell_name=`basename ${bash_source}`
#修改这里jar包名即可
jar_name="xxxxxxxxxxxx.jar"
jar_path=$cur_shell_dir/$jar_name
#java_mem_opts=" -server -xms1024m -xmx1024m -xx:permsize=128m"
java_mem_opts=""
#spring_profiles_activ="-dspring.profiles.active=eureka2"
spring_profiles_activ=""
log_dir=$cur_shell_dir/logs
log_path=$log_dir/${jar_name}.log
echo_help()
{
echo -e "syntax: sh $cur_shell_name start|stop"
}
if [ -z $1 ];then
echo_help
exit 1
fi
if [ ! -d "$log_dir" ];then
mkdir "$log_dir"
fi
if [ ! -f "$log_path" ];then
touch "$log_dir"
fi
if [ "$1" == "start" ];then
# check server
pids=`ps --no-heading -c java -f --width 1000 | grep $jar_name | awk '{print $2}'`
if [ -n "$pids" ]; then
echo -e "error: the $jar_name already started and the pid is ${pids}."
exit 1
fi
echo "starting the $jar_name..."
# start
nohup java $java_mem_opts -jar $spring_profiles_activ $jar_path >> $log_path 2>&1 &
count=0
while [ $count -lt 1 ]; do
sleep 1
count=`ps --no-heading -c java -f --width 1000 | grep "$jar_name" | awk '{print $2}' | wc -l`
if [ $count -gt 0 ]; then
break
fi
done
pids=`ps --no-heading -c java -f --width 1000 | grep "$jar_name" | awk '{print $2}'`
echo "${jar_name} started and the pid is ${pids}."
echo "you can check the log file in ${log_path} for details."
elif [ "$1" == "stop" ];then
pids=`ps --no-heading -c java -f --width 1000 | grep $jar_name | awk '{print $2}'`
if [ -z "$pids" ]; then
echo "error:the $jar_name does not started!"
exit 1
fi
echo -e "stopping the $jar_name..."
for pid in $pids; do
kill $pid > /dev/null 2>&1
done
count=0
while [ $count -lt 1 ]; do
sleep 1
count=1
for pid in $pids ; do
pid_exist=`ps --no-heading -p $pid`
if [ -n "$pid_exist" ]; then
count=0
break
fi
done
done
echo -e "${jar_name} stopped and the pid is ${pids}."
else
echo_help
exit 1
fi以上代码只需修改jar包名即可使用
启动jar包:
./xxxx.sh start
停止 jar包
./xxxx.sh stop
作者最新文章
赤友清理大师
2026-09-16 17:43
南邮光擎智算团队:GaN基Micro-LED光计算芯片从理论到流片的突破
2026-09-08 18:35
多张照片怎么合成PDF文件?三种图片转PDF工具怎么选?
2026-09-03 17:04
Excel转PDF防乱版指南:在线与本地双方案及排版检查
2026-09-03 10:04
多个PDF怎么合并成一个?合并后顺序怎么检查?
2026-09-02 19:54
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多
Windows 10
Windows
Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。
极度公式
Windows/macOS/Linux
极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。
















