Liunx下 java jar包的批量启动、停止、重启 sh脚本


#!/bin/sh
export SERVER1=SERVER1-0.0.1-SNAPSHOT.jar
export SERVER2=SERVER2-0.0.1-SNAPSHOT.jar

export SERVER1_port=8081
export SERVER2_port=8082
 
start)
        ## 启动SERVER1
        echo "--------SERVER1 开始启动--------------"
        nohup java -Xms800m -Xmx800m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -jar $SERVER1 --server.port=$SERVER1_pid >/dev/null 2>&1 &
        SERVER1_pid=`lsof -i:$SERVER1_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$SERVER1_pid" ]
            do
              SERVER1_pid=`lsof -i:$SERVER1_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "SERVER1 pid is $SERVER1_pid" 
        echo "--------SERVER1 启动成功--------------"
		
		  ## 启动SERVER2
        echo "--------开始启动SERVER2---------------"
        nohup java -Xms800m -Xmx800m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m -jar $SERVER2 --server.port=$SERVER2_pid  >/dev/null 2>&1 &
        SERVER2_pid=`lsof -i:$SERVER2_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$SERVER2_pid" ]
            do
              SERVER2_pid=`lsof -i:$SERVER2_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "SERVER2 pid is $SERVER2_pid"     
        echo "---------SERVER2 启动成功-----------"
 
 	
		
        echo "===startAll success==="
        ;;
 
 stop)
        
        P_ID=`ps -ef | grep -w $SERVER1 | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===SERVER1 process not exists or stop success"
        else
            kill -9 $P_ID
            echo "SERVER1 killed success"
        fi
		
		P_ID=`ps -ef | grep -w $SERVER2 | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===SERVER2 process not exists or stop success"
        else
            kill -9 $P_ID
            echo "SERVER2 killed success"
        fi
	
		
        echo "===stop success==="
        ;;   
 
restart)
        $0 stop
        sleep 2
        $0 start
        echo "===restart success==="
        ;;   
esac	
exit 0

你可能感兴趣的:(Java,Linux,linux,jar,java)