Linux按顺序启动多个jar的shell脚本

#!/bin/sh
export EUREKA=pigx-eureka.jar
export CONFIG=pigx-config.jar
export GATEWAY=pigx-gateway.jar
export AUTH=pigx-auth.jar
export UPMS=pigx-upms-biz.jar

export EUREKA_port=8761
export CONFIG_port=8888
export GATEWAY_port=9999
export AUTH_port=3000
export UPMS_port=4000

case "$1" in

start)
        ## 启动eureka
        echo "--------eureka 开始启动--------------"
        nohup java -jar $EUREKA &
        EUREKA_pid=`lsof -i:$EUREKA_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$EUREKA_pid" ]
            do
              EUREKA_pid=`lsof -i:$EUREKA_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "EUREKA pid is $EUREKA_pid" 
        echo "--------eureka 启动成功--------------"
 
        ## 启动config
        echo "--------开始启动CONFIG---------------"
        nohup java -jar $CONFIG &
        CONFIG_pid=`lsof -i:$CONFIG_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$CONFIG_pid" ]
            do
              CONFIG_pid=`lsof -i:$CONFIG_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "CONFIG pid is $CONFIG_pid" 
     sleep 10 echo
"---------CONFIG 启动成功-----------" ## 启动gateway echo "--------开始启动GATEWAY---------------" nohup java -jar $GATEWAY & GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'` until [ -n "$GATEWAY_pid" ] do GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'` done echo "GATEWAY pid is $GATEWAY_pid" echo "---------GATEWAY 启动成功-----------" ## 启动auth echo "--------开始启动AUTH---------------" nohup java -jar $AUTH & AUTH_pid=`lsof -i:$AUTH_port|grep "LISTEN"|awk '{print $2}'` until [ -n "$AUTH_pid" ] do AUTH_pid=`lsof -i:$AUTH_port|grep "LISTEN"|awk '{print $2}'` done echo "AUTH pid is $AUTH_pid" echo "---------AUTH 启动成功-----------" ## 启动upms echo "--------开始启动UPMS---------------" nohup java -jar $UPMS & UPMS_pid=`lsof -i:$UPMS_port|grep "LISTEN"|awk '{print $2}'` until [ -n "$UPMS_pid" ] do UPMS_pid=`lsof -i:$UPMS_port|grep "LISTEN"|awk '{print $2}'` done echo "UPMS pid is $UPMS_pid" echo "---------UPMS 启动成功-----------" echo "===startAll success===" ;; stop) P_ID=`ps -ef | grep -w $EUREKA | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "===EUREKA process not exists or stop success" else kill -9 $P_ID echo "EUREKA killed success" fi P_ID=`ps -ef | grep -w $CONFIG | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "===CONFIG process not exists or stop success" else kill -9 $P_ID echo "CONFIG killed success" fi P_ID=`ps -ef | grep -w $GATEWAY | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "===GATEWAY process not exists or stop success" else kill -9 $P_ID echo "GATEWAY killed success" fi P_ID=`ps -ef | grep -w $AUTH | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "===AUTH process not exists or stop success" else kill -9 $P_ID echo "AUTH killed success" fi P_ID=`ps -ef | grep -w $UPMS | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "===UPMS process not exists or stop success" else kill -9 $P_ID echo "UPMS killed success" fi echo "===stop success===" ;; restart) $0 stop sleep 2 $0 start echo "===restart success===" ;; esac exit 0

注:lsof命令需要安装

转载于:https://www.cnblogs.com/fangts/p/10683121.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值