springboot 批量jar包启动脚本2

#!/bin/sh

export ROOT_DIR=`pwd`/jar
echo "--------ROOT_DIR $ROOT_DIR--------------"
export REGISTER=$ROOT_DIR/xxxx-register/target/xxxx-register-0.0.1-SNAPSHOT.jar
export CONFIG=$ROOT_DIR/xxxx-config/target/xxxx-config-0.0.1-SNAPSHOT.jar
export GATEWAY=$ROOT_DIR/xxxx-gateway/target/xxxx-gateway-0.0.1-SNAPSHOT.jar
export AUTH=$ROOT_DIR/xxxx-auth/target/xxxx-auth-0.0.1-SNAPSHOT.jar
export UPMS=$ROOT_DIR/xxxx-upms/target/xxxx-upms-0.0.1-SNAPSHOT.jar
export SCHEDULE=$ROOT_DIR/xxxx-schedule/target/xxxx-schedule-0.0.1-SNAPSHOT.jar
export FILE=$ROOT_DIR/xxxx-file/target/xxxx-file-0.0.1-SNAPSHOT.jar
export MESSAGE=$ROOT_DIR/xxxx-message/message-service/target/message-service-0.0.1-SNAPSHOT.jar
export APP=$ROOT_DIR/xxxx-modules/app-service/target/app-service-0.0.1-SNAPSHOT.jar
export ADM=$ROOT_DIR/xxxx-modules/adm-service/target/adm-service-0.0.1-SNAPSHOT.jar
export PERSONNEL=$ROOT_DIR/xxxx-modules/personnel-service/target/personnel-service-0.0.1-SNAPSHOT.jar
export POWER=$ROOT_DIR/xxxx-modules/power-service/target/power-service-0.0.1-SNAPSHOT.jar
 
export CONFIG_port=9060
export REGISTER_port=9061
export AUTH_port=9062
export GATEWAY_port=9063
export UPMS_port=9064
export MESSAGE_port=9065
export FILE_port=9066
export SCHEDULE_port=9067
export POWER_port=9071
export PERSONNEL_port=9072
export APP_port=9073
export ADM_port=9074


case "$1" in
 
start)
        ## 启动xxxx-register
        echo "--------xxxx-register 开始启动--------------"
        nohup java -Xms256m -Xmx256m -jar $REGISTER 1>>./nohup.log 2>&1 &
        REGISTER_pid=`lsof -i:$REGISTER_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$REGISTER_pid" ]
            do
              REGISTER_pid=`lsof -i:$REGISTER_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "xxxx-register pid is $REGISTER_pid" 
        echo "--------xxxx-register 启动成功--------------"
        
        ## 启动xxxx-config
        echo "--------开始启动xxxx-config---------------"
        nohup java -Xms256m -Xmx256m -jar $CONFIG 1>>./nohup.log 2>&1 &
        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 "xxxx-config pid is $CONFIG_pid"     
        echo "---------xxxx-config 启动成功-----------"
 
    # 睡眠30s
    echo "---------睡眠30s-----------"
    sleep 30s
        
        ## 启动xxxx-gateway
        echo "--------开始启动xxxx-gateway---------------"
        nohup java -Xms256m -Xmx256m -jar $GATEWAY 1>>./nohup.log 2>&1 &
        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 "---------xxxx-gateway 启动成功-----------"
 
        ## 启动xxxx-auth
        echo "--------开始启动xxxx-auth---------------"
        nohup java -Xms256m -Xmx256m -jar $AUTH 1>>./nohup.log 2>&1 &
        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 "xxxx-auth pid is $AUTH_pid"     
        echo "---------xxxx-auth 启动成功-----------"
        
        ## 启动xxxx-upms
        echo "--------开始启动xxxx-upms---------------"
        nohup java -Xms256m -Xmx256m -jar $UPMS 1>>./nohup.log 2>&1 &
        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 "xxxx-upms pid is $UPMS_pid"     
        echo "---------xxxx-upms 启动成功-----------"
        
        ## 启动xxxx-schedule
        echo "--------开始启动xxxx-schedule---------------"
        nohup java -Xms256m -Xmx256m -jar $SCHEDULE 1>>./nohup.log 2>&1 &
        SCHEDULE_pid=`lsof -i:$SCHEDULE_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$SCHEDULE_pid" ]
            do
              SCHEDULE_pid=`lsof -i:$SCHEDULE_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "xxxx-schedule pid is $SCHEDULE_pid"     
        echo "---------xxxx-schedule 启动成功-----------"
        
        ## 启动xxxx-file
        echo "--------开始启动xxxx-file---------------"
        nohup java -Xms256m -Xmx256m -jar $FILE 1>>./nohup.log 2>&1 &
        FILE_pid=`lsof -i:$FILE_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$FILE_pid" ]
            do
              FILE_pid=`lsof -i:$FILE_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "xxxx-file pid is $FILE_pid"     
        echo "---------xxxx-file 启动成功-----------"
        
        ## 启动message-service
        echo "--------开始启动message-service---------------"
        nohup java -Xms256m -Xmx256m -jar $MESSAGE 1>>./nohup.log 2>&1 &
        MESSAGE_pid=`lsof -i:$MESSAGE_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$MESSAGE_pid" ]
            do
              MESSAGE_pid=`lsof -i:$MESSAGE_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "message-service pid is $MESSAGE_pid"     
        echo "---------message-service 启动成功-----------"
        
        ## 启动app-service
        echo "--------开始启动app-service---------------"
        nohup java -Xms256m -Xmx256m -jar $APP 1>>./nohup.log 2>&1 &
        APP_pid=`lsof -i:$APP_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$APP_pid" ]
            do
              APP_pid=`lsof -i:$APP_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "app-service pid is $APP_pid"     
        echo "---------app-service 启动成功-----------"
        
        ## 启动adm-service
        echo "--------开始启动adm-service---------------"
        nohup java -Xms256m -Xmx256m -jar $ADM 1>>./nohup.log 2>&1 &
        ADM_pid=`lsof -i:$ADM_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$ADM_pid" ]
            do
              ADM_pid=`lsof -i:$ADM_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "adm-service pid is $ADM_pid"     
        echo "---------adm-service 启动成功-----------"
        
        ## 启动personnel-service
        echo "--------开始启动personnel-service---------------"
        nohup java -Xms256m -Xmx256m -jar $PERSONNEL 1>>./nohup.log 2>&1 &
        PERSONNEL_pid=`lsof -i:$PERSONNEL_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$PERSONNEL_pid" ]
            do
              PERSONNEL_pid=`lsof -i:$PERSONNEL_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "personnel-service pid is $PERSONNEL_pid"     
        echo "---------personnel-service 启动成功-----------"
        
        ## 启动power-service
        echo "--------开始启动power-service---------------"
        nohup java -Xms256m -Xmx256m -jar $POWER 1>>./nohup.log 2>&1 &
        POWER_pid=`lsof -i:$POWER_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$POWER_pid" ]
            do
              POWER_pid=`lsof -i:$POWER_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "power-service pid is $POWER_pid"     
        echo "---------power-service 启动成功-----------"
    
        echo "===startAll success==="
        ;;
 
 stop)
        P_ID=`ps -ef | grep -w $REGISTER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===REGISTER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "REGISTER 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
 
        P_ID=`ps -ef | grep -w $SCHEDULE | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===SCHEDULE process not exists or stop success"
        else
            kill -9 $P_ID
            echo "SCHEDULE killed success"
        fi
        
        P_ID=`ps -ef | grep -w $FILE | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===FILE process not exists or stop success"
        else
            kill -9 $P_ID
            echo "FILE killed success"
        fi
 
        P_ID=`ps -ef | grep -w $MESSAGE | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===MESSAGE process not exists or stop success"
        else
            kill -9 $P_ID
            echo "MESSAGE killed success"
        fi
 
        P_ID=`ps -ef | grep -w $APP | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===APP process not exists or stop success"
        else
            kill -9 $P_ID
            echo "APP killed success"
        fi
 
        P_ID=`ps -ef | grep -w $ADM | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===ADM process not exists or stop success"
        else
            kill -9 $P_ID
            echo "ADM killed success"
        fi
 
        P_ID=`ps -ef | grep -w $PERSONNEL | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===PERSONNEL process not exists or stop success"
        else
            kill -9 $P_ID
            echo "PERSONNEL killed success"
        fi
 
 
        P_ID=`ps -ef | grep -w $POWER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===POWER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "POWER killed success"
        fi
 
        echo "===stop success==="
        ;;   
 
restart)
        $0 stop
        sleep 5
        $0 start
        echo "===restart success==="
        ;;   
esac    


你可能感兴趣的:(springboot 批量jar包启动脚本2)