liunx的jar包停止shell脚本

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32447301/article/details/82598359

一、第一种方式
1.jar启动shell命令

mkdir startUp.sh                # 创建.sh脚本
chmod 777  startUp.sh           # 加权限
./startUp.sh                    # 启动

startUp.sh的shell内容

java -jar xxxx.jar &            # 注意:必须有&让其后台执行,否则没有pid生成
echo $! > test.pid              # 将jar包启动对应的pid写入文件中,为停止时提供pid

2.jar停止shell命令

mkdir stopUp.sh           # 创建.sh脚本
./stopUp.sh               # 启动      

stopUp.sh的shell内容

PID=$(cat test.pid)       # 搜索pid
kill -9 $PID              # 删除 pid

二、第二种
1.后缀没有&的启动方式 同时使用screen启动

mkdir stopUp.sh           # 创建.sh脚本
./stopUp.sh               # 启动      

startUp.sh的shell内容

#!/bin/sh
if [ -z "$STY"]; then exec screen -dm -s push /bin/sh "$0"; fi
cd /home/xxxx
java -jar xxxxjar > ../logs/error.log

2.停止jar命令运行

mkdir stopUp.sh    # 创建.sh脚本
./stopUp.sh        # 启动 

stopUp.sh的shell内容:

#!/bin/sh
screen  -S push  -X quit

三、第三种

screen -ls 

There is a screen on:
    30339.pyapi (Detached)
1 Socket in /var/run/screen/S-root.

screen -r 30339        #进入要中断的screen

exit        #exit 或者 control +c 退出 screen

《参考:https://blog.csdn.net/zhengyong15984285623/article/details/49866373
《参考:https://blog.csdn.net/qq_28018283/article/details/78027229

猜你喜欢

转载自blog.csdn.net/qq_32447301/article/details/82598359
今日推荐