linux启动脚本springboot,Linux 启动停止SpringBoot jar 程序部署Shell 脚本的方法

废话不多说了,先给大家上代码,具体代码如下所示:

#!/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

总结

以上所述是小编给大家介绍的linux 启动停止springboot jar 程序部署shell 脚本的方法,希望对大家有所帮助

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值