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
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值