项目执行shell脚本

#!/bin/sh
export PROFILE=dev
export JINLI_CONFIG_PASSWORD=jinli
export JINLI_ACCOUNT_PASSWORD=jinli
export JINLI_BUSINESS_PASSWORD=jinli
export JINLI_CONFIG_PORT=8888
export JINLI_REGISTRY_PORT=8761
export JINLI_AUTH_PORT=4000
export JINLI_ACCOUNT_PORT=5000
export JINLI_BUSINESS_PORT=7000
export JINLI_ZUUL_PORT=8080
export JAVA_HOME=/home/jdk/jdk1.8.0_271

case "$1" in
start)
    case "$2" in
        jinli-config)
            echo "jinli-config starting ..."
            nohup $JAVA_HOME/bin/java -jar -Xmx200m $(dirname $0)/jinli-config.jar >/dev/null 2>&1 &
            JINLI_CONFIG_PID=`lsof -i:$JINLI_CONFIG_PORT|grep "LISTEN"|awk '{print $2}'`
        ## -n 字符串长度大于1 grep "listen" 取出改字符所在的行, awk 取出第二个参数
until [ -n "$JINLI_CONFIG_PID" ] do JINLI_CONFIG_PID=`lsof -i:$JINLI_CONFIG_PORT|grep "LISTEN"|awk '{print $2}'` done echo "jinli-config started, pid is $JINLI_CONFIG_PID" ;; jinli-registry) echo "jinli-registry starting ..." nohup $JAVA_HOME/bin/java -jar -Xmx256m $(dirname $0)/jinli-registry.jar >/dev/null 2>&1 & JINLI_REGISTRY_PID=`lsof -i:$JINLI_REGISTRY_PORT|grep "LISTEN"|awk '{print $2}'` until [ -n "$JINLI_REGISTRY_PID" ] do JINLI_REGISTRY_PID=`lsof -i:$JINLI_REGISTRY_PORT|grep "LISTEN"|awk '{print $2}'` done echo "jinli-registry started, pid is $JINLI_REGISTRY_PID" ;; jinli-auth) echo "jinli-auth starting ..." nohup $JAVA_HOME/bin/java -jar -Dspring.profiles.active=$PROFILE -Xmx200m $(dirname $0)/jinli-auth.jar >/dev/null 2>&1 & JINLI_AUTH_PID=`lsof -i:$JINLI_AUTH_PORT|grep "LISTEN"|awk '{print $2}'` until [ -n "$JINLI_AUTH_PID" ] do JINLI_AUTH_PID=`lsof -i:$JINLI_AUTH_PORT|grep "LISTEN"|awk '{print $2}'` done echo "jinli-auth started, pid is $JINLI_AUTH_PID" ;; jinli-account) echo "jinli-account starting ..." nohup $JAVA_HOME/bin/java -jar -Dspring.profiles.active=$PROFILE -Xmx200m $(dirname $0)/jinli-account.jar >/dev/null 2>&1 & JINLI_ACCOUNT_PID=`lsof -i:$JINLI_ACCOUNT_PORT|grep "LISTEN"|awk '{print $2}'` until [ -n "$JINLI_ACCOUNT_PID" ] do JINLI_ACCOUNT_PID=`lsof -i:$JINLI_ACCOUNT_PORT|grep "LISTEN"|awk '{print $2}'` done echo "jinli-account started, pid is $JINLI_ACCOUNT_PID" ;; jinli-business) echo "jinli-business starting ..." nohup $JAVA_HOME/bin/java -jar -Dspring.profiles.active=$PROFILE -Xmx200m $(dirname $0)/jinli-business.jar >/dev/null 2>&1 & JINLI_BUSINESS_PID=`lsof -i:$JINLI_BUSINESS_PORT|grep "LISTEN"|awk '{print $2}'` until [ -n "$JINLI_BUSINESS_PID" ] do JINLI_BUSINESS_PID=`lsof -i:$JINLI_BUSINESS_PORT|grep "LISTEN"|awk '{print $2}'` done echo "jinli-business started, pid is $JINLI_BUSINESS_PID" ;; jinli-zuul) echo "jinli-zuul starting ..." nohup $JAVA_HOME/bin/java -jar -Dspring.profiles.active=$PROFILE -Xmx200m $(dirname $0)/jinli-zuul.jar >/dev/null 2>&1 & JINLI_ZUUL_PID=`lsof -i:$JINLI_ZUUL_PORT|grep "LISTEN"|awk '{print $2}'` until [ -n "$JINLI_ZUUL_PID" ] do JINLI_ZUUL_PID=`lsof -i:$JINLI_ZUUL_PORT|grep "LISTEN"|awk '{print $2}'` done echo "jinli-zuul started, pid is $JINLI_ZUUL_PID" ;; *)
      ## $0 代表文件名 如果没有第二个参数 那么依次执行以下命令 $
0 start jinli-config $0 start jinli-registry $0 start jinli-auth $0 start jinli-account $0 start jinli-business $0 start jinli-zuul echo "JINLI started success" ;; esac ;; stop) case "$2" in jinli-config) P_ID=`ps -ef | grep -w jinli-config.jar | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "jinli-config process not exists or stop success" else kill -9 $P_ID echo "jinli-config killed success" fi ;; jinli-registry) P_ID=`ps -ef | grep -w jinli-registry.jar | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "jinli-registry process not exists or stop success" else kill -9 $P_ID echo "jinli-registry killed success" fi ;; jinli-auth) P_ID=`ps -ef | grep -w jinli-auth.jar | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "jinli-authprocess not exists or stop success" else kill -9 $P_ID echo "jinli-auth killed success" fi ;; jinli-account) P_ID=`ps -ef | grep -w jinli-account.jar | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "jinli-account process not exists or stop success" else kill -9 $P_ID echo "jinli-account killed success" fi ;; jinli-business) P_ID=`ps -ef | grep -w jinli-business.jar | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "jinli-business process not exists or stop success" else kill -9 $P_ID echo "jinli-business killed success" fi ;; jinli-zuul) P_ID=`ps -ef | grep -w jinli-zuul.jar | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "jinli-zuul process not exists or stop success" else kill -9 $P_ID echo "jinli-zuul killed success" fi ;; *) $0 stop jinli-config $0 stop jinli-registry $0 stop jinli-auth $0 stop jinli-account $0 stop jinli-business $0 stop jinli-zuul echo "JINLI stopped success" ;; esac ;; restart) $0 stop sleep 2 $0 start echo "JINLI restarted success" ;; *) echo "Usage: `basename $0` start|stop|restart [jinli-config | jinli-registry | jinli-auth | jinli-account | jinli-business | jinli-zuul]" ;; esac exit 0
原文地址:https://www.cnblogs.com/wcss/p/14120642.html