#!/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命令需要安装