linux 批量执行nohup java -jar 命令

#!/bin/sh
export items=box_items_service-1.0.jar
export marketing=box_marketing_service-1.0.jar
export member=box_member_service-1.0.jar
export merchants=box_merchants_service-1.0.jar
export transaction=box_transaction_service-1.0.jar
export manage=box_manage_gather-1.0.jar
export manageGateway=box_manage_gateway-1.0.jar

export items_port=8007
export marketing_port=8008
export member_port=8005
export merchants_port=8009
export transaction_port=8006
export manage_port=8004
export manageGateway_port=8002

case "$1" in
 
start)
        ## 启动商品服务
        echo "--------box_items_service 开始启动--------------"
		nohup java -jar $items --spring.profiles.active=pro >/dev/null 2>&1 &
        items_pid=`lsof -i:$items_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$items_pid" ]
            do
              items_pid=`lsof -i:$items_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "box_items_service pid is $items_port" 
        echo "--------box_items_service 启动成功--------------"
        
        ## 启动营销服务
        echo "--------box_marketing_service 开始启动--------------"
		nohup java -jar $marketing --spring.profiles.active=pro >/dev/null 2>&1 &
        marketing_pid=`lsof -i:$marketing_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$marketing_pid" ]
            do
              marketing_pid=`lsof -i:$marketing_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "box_marketing_service pid is $marketing_port" 
        echo "--------box_marketing_service 启动成功--------------"
        
		## 启动会员服务
        echo "--------box_member_service 开始启动--------------"
		nohup java -jar $member --spring.profiles.active=pro >/dev/null 2>&1 &
        member_pid=`lsof -i:$member_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$member_pid" ]
            do
              member_pid=`lsof -i:$member_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "box_member_service pid is $member_port" 
        echo "--------box_member_service 启动成功--------------"	
        
        ## 启动商家服务
        echo "--------box_merchants_service 开始启动--------------"
		nohup java -jar $merchants --spring.profiles.active=pro >/dev/null 2>&1 &
        merchants_pid=`lsof -i:$merchants_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$merchants_pid" ]
            do
              merchants_pid=`lsof -i:$merchants_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "box_merchants_service pid is $merchants_port" 
        echo "--------box_merchants_service 启动成功--------------"	
		
		## 启动交易服务
        echo "--------box_transaction_service 开始启动--------------"
		nohup java -jar $transaction --spring.profiles.active=pro >/dev/null 2>&1 &
        transaction_pid=`lsof -i:$transaction_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$transaction_pid" ]
            do
              transaction_pid=`lsof -i:$transaction_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "box_transaction_service pid is $transaction_port" 
        echo "--------box_transaction_service 启动成功--------------"	
		
		
		## 启动管理聚合服务
        echo "--------box_manage_gather 开始启动--------------"
		nohup java -jar $manage --spring.profiles.active=pro >/dev/null 2>&1 &
        manage_pid=`lsof -i:$manage_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$manage_pid" ]
            do
              manage_pid=`lsof -i:$manage_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "box_manage_gather pid is $manage_port" 
        echo "--------box_manage_gather 启动成功--------------"	
        
        
        ## 启动管理网关服务
        echo "--------box_manage_gateway 开始启动--------------"
		nohup java -jar $manageGateway --spring.profiles.active=pro >/dev/null 2>&1 &
        manageGateway_pid=`lsof -i:$manageGateway_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$manageGateway_pid" ]
            do
              manageGateway_pid=`lsof -i:$manageGateway_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "box_manage_gateway pid is $manageGateway_port" 
        echo "--------box_manage_gateway 启动成功--------------"	
		
		
        echo "===startAll success==="
        ;;
 
 stop)
        
        ## 聚合 和 网关 必须先停掉
        
         P_ID=`ps -ef | grep -w $manageGateway | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===box_manage_gateway process not exists or stop success"
        else
            kill -9 $P_ID
            echo "box_manage_gateway killed success"
        fi
        
        P_ID=`ps -ef | grep -w $manage | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===box_manage_gather process not exists or stop success"
        else
            kill -9 $P_ID
            echo "box_manage_gather killed success"
        fi
        
        
        P_ID=`ps -ef | grep -w $items | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===box_items_service process not exists or stop success"
        else
            kill -9 $P_ID
            echo "box_items_service killed success"
        fi
		
		
		P_ID=`ps -ef | grep -w $marketing | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===box_marketing_service process not exists or stop success"
        else
            kill -9 $P_ID
            echo "box_marketing_service killed success"
        fi
		
		
		P_ID=`ps -ef | grep -w $member | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===box_member_service process not exists or stop success"
        else
            kill -9 $P_ID
            echo "box_member_service killed success"
        fi
        
        
        P_ID=`ps -ef | grep -w $merchants | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===box_merchants_service process not exists or stop success"
        else
            kill -9 $P_ID
            echo "box_merchants_service killed success"
        fi
        
        P_ID=`ps -ef | grep -w $transaction | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===box_transaction_service process not exists or stop success"
        else
            kill -9 $P_ID
            echo "box_transaction_service killed success"
        fi
 
        echo "===stop success==="
        ;;   
 
restart)
        $0 stop
        sleep 2
        $0 start
        echo "===restart success==="
        ;;   
esac	
exit 0


 #启动:sh boxService.sh start
 #停止:sh boxService.sh stop
 #重新:sh boxService.sh restart

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: nohup java -jar命令是在Linux系统中运行Java程序的命令。其中,nohup表示不挂断地运行命令,即使终端关闭也不会停止程序的运行;java表示运行Java程序;-jar表示运行一个打包成jar文件的Java程序。 具体来说,nohup java -jar命令可以在后台运行一个Java程序,而不会受到终端关闭等操作的影响。这对于需要长时间运行的程序非常有用,比如服务器端的应用程序。 需要注意的是,nohup java -jar命令需要在Linux系统中使用,而且需要安装Java环境。同时,需要将Java程序打包成jar文件才能使用该命令运行。 ### 回答2: nohup java -jar命令是一个常用的命令,用于在后台运行Java应用程序。它的作用是让Java应用程序在用户退出登录后继续运行,并且不受挂起信号的影响。 nohup命令是词组“no hang up”的缩写,表示不挂断。nohup命令后紧跟着的是要在后台运行的命令,本例中是java -jar命令。这个命令指定使用Java虚拟机(JVM)来运行一个以jar包形式打包的Java应用程序。 使用nohup java -jar命令有很多好处。首先,它可以让Java应用程序在后台持续运行,即使您退出了登录。其次,它可以防止Java应用程序被终止,即使系统发送了中断信号或挂起信号。此外,nohup命令还会将输出信息保存到一个文件中。默认情况下,该文件名为nohup.out,但是您可以使用重定向运算符(>)将它重定向到其他文件。 举个例子,如果您想在Linux系统上运行一个名为myapp.jarJava应用程序,您可以使用以下命令nohup java -jar myapp.jar & 此命令将启动myapp.jar并将其放在后台运行,同时也将输出信息保存到nohup.out文件中。要停止该应用程序,请使用kill命令。 总之,nohup java -jar命令使得Java应用程序可以在后台持续运行,并且不会被系统中断。它是一个非常有用的命令,可以为Java开发者提供方便和保障。 ### 回答3: nohup java -jar命令Linux系统中常用的命令,它可以让我们在后台运行Java应用程序。下面对该命令进行详细解析: 1. nohup命令 nohup是No Hang Up的缩写,意思是不挂断。它的作用是让我们在后台运行命令时,即使断开终端连接,命令还是能够继续运行,直到执行完毕。 2. java -jar命令 java -jar命令是运行Java应用程序的命令,其中-jar参数表示运行一个打包的Java应用程序。使用该命令可以忽略classpath环境变量和-classpath命令行选项,方便我们打包和运行Java应用程序。 3. 组合使用 nohup java -jar命令的组合使用,可以让我们在后台运行Java应用程序,且即使断开终端连接,应用程序也能够继续运行。使用该命令时,需要指定Java应用程序的jar包路径,如下所示: nohup java -jar /path/to/app.jar & 其中,&表示将命令放入后台运行。 除了上述常见用法外,nohup java -jar命令还可以搭配其他命令使用,如结合grep命令Java应用程序输出的日志进行过滤,或者使用tee命令将日志保存到文件中。 总之,nohup java -jar命令是在Linux系统中常用的命令,它能够在后台运行Java应用程序,并且即使断开终端连接,应用程序也能够继续运行,非常方便实用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值