SGTMS

做事情
我们是认真的
您的位置:SGTMS>Linux>Linux批量启动shell脚本

Linux批量启动shell脚本

前言

分享一个jar包批量启动的shell脚本,可根据需求自行在此基础上修改,可以在日常运维中节省不少的时间,可实现程序批start,批量stop,restart等。

正文

#!/bin/sh
export EUREKA=eurekaserver.jar
export CONFIG=configserver.jar
export GATEWAY=zuulgatewayserver.jar
export AUTH=authorizeserver.jar
export LOG=logstatisticsserver.jar
export APPMGR=appmgrserver.jar
export ORGANIZEUSER=organizeuserserver.jar
export JTMOP=jtmopserver.jar

export EUREKA_log=../logs/eurekaserver.log
export CONFIG_log=../logs/configserver.log
export GATEWAY_log=../logs/zuulgatewayserver.log
export AUTH_log=../logs/authorizeserver.log
export LOG_log=../logs/logstatisticsserver.log
export APPMGR_log=../logs/appmgrserver.log
export ORGANIZEUSER_log=../logs/organizeuserserver.log
export JTMOP_log=../logs/jtmopserver.log

export EUREKA_port=10080
export CONFIG_port=10085
export GATEWAY_port=10084
export AUTH_port=10088
export LOG_port=10093
export APPMGR_port=10092
export ORGANIZEUSER_port=10087
export JTMOP_port=10091

case "$1" in

start)
        ## 启动eureka
        echo "--------eureka 开始启动--------------"
        nohup java -jar $EUREKA > $EUREKA_log 2>&1 &
        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"
        sleep 10
        echo "--------eureka 启动成功--------------"
 
        ## 启动config
        echo "--------开始启动CONFIG---------------"
        nohup java -jar $CONFIG > $CONFIG_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 "CONFIG pid is $CONFIG_pid"
        sleep 30
        echo "---------CONFIG 启动成功-----------"
 
        ## 启动gateway
        echo "--------开始启动GATEWAY---------------"
        nohup java -jar $GATEWAY > $GATEWAY_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 "---------GATEWAY 启动成功-----------"
 
        ## 启动auth
        echo "--------开始启动AUTH---------------"
        nohup java -jar $AUTH > $AUTH_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 "AUTH pid is $AUTH_pid"     
        echo "---------AUTH 启动成功-----------"
                 
        ## 启动log
        echo "--------开始启动LOG---------------"
        nohup java -jar $LOG > $LOG_log 2>&1 &
        LOG_pid=`lsof -i:$LOG_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$LOG_pid" ]
            do
              LOG_pid=`lsof -i:$LOG_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "LOG pid is $LOG_pid"     
        echo "---------LOG 启动成功-----------"
        
        ## 启动appmgr
        echo "--------开始启动APPMGR---------------"
        nohup java -jar $APPMGR > $APPMGR_log 2>&1 &
        APPMGR_pid=`lsof -i:$APPMGR_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$APPMGR_pid" ]
            do
              APPMGR_pid=`lsof -i:$APPMGR_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "APPMGR pid is $APPMGR_pid"     
        echo "---------APPMGR 启动成功-----------"
        
        ## 启动organizeuser
        echo "--------开始启动ORGANIZEUSER---------------"
        nohup java -jar $ORGANIZEUSER > $ORGANIZEUSER_log 2>&1 &
        ORGANIZEUSER_pid=`lsof -i:$ORGANIZEUSER_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$ORGANIZEUSER_pid" ]
            do
              ORGANIZEUSER_pid=`lsof -i:$ORGANIZEUSER_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "ORGANIZEUSER pid is $ORGANIZEUSER_pid"     
        echo "---------ORGANIZEUSER 启动成功-----------"
        
        ## 启动jtmop
        echo "--------开始启动JTMOP---------------"
        nohup java -jar $JTMOP > $JTMOP_log 2>&1 &
        JTMOP_pid=`lsof -i:$JTMOP_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$JTMOP_pid" ]
            do
              JTMOP_pid=`lsof -i:$JTMOP_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "JTMOP pid is $JTMOP_pid"     
        echo "---------JTMOP 启动成功-----------"
        
        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 $LOG | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===LOG process not exists or stop success"
        else
            kill -9 $P_ID
            echo "LOG killed success"
        fi
        
         P_ID=`ps -ef | grep -w $APPMGR | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===APPMGR process not exists or stop success"
        else
            kill -9 $P_ID
            echo "APPMGR killed success"
        fi
        
         P_ID=`ps -ef | grep -w $ORGANIZEUSER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===ORGANIZEUSER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "ORGANIZEUSER killed success"
        fi
        
         P_ID=`ps -ef | grep -w $JTMOP | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===JTMOP process not exists or stop success"
        else
            kill -9 $P_ID
            echo "JTMOP killed success"
        fi
 
        echo "===stop success==="
        ;;   
 
restart)
        $0 stop
        sleep 10
        $0 start
        echo "===restart success==="
        ;;   
esac    
exit 0
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《Linux批量启动shell脚本》
文章链接: https://www.sgtms.com/linux/69.html
本站资源仅供个人学习交流,转载或者引用本文内容请注明来源及作者,不允许用于商业用途。
分享到:

相关推荐

网友评论抢沙发

路人甲 表情
Ctrl+Enter快速提交