Shell 简单的java微服务jar包 -- 启动脚本

#!/bin/bash

# 接收服务名
PJT_name=$1
PJT_DIR=/apps/project/
# 接受 start status stop 参数
service=$2
# 获取主机名判断Eureka服务启动的 参数
HOSTNAME=`hostname`
dic=("grab_cycle_eureka" "grab_cycle_ubikeuser1" "grab_cycle_config" "grab_cycle_gateway" "grab_cycle_ubikeuser" "grab_cycle_timing" "grab_cycle_MKexternal" "grab_cycle_MKcore" "grab_cycle_MKpay" "grab_cycle_MKstatistic" "grab_cycle_MKridingorder" "grab_cycle_MKfeedback" "grab_cycle_MKjarvis" "grab_cycle_MKbike" "grab_cycle_ubikelock" "grab_cycle_ubikeinfra" "grab_cycle_ubikeHwtest" "grab_cycle_WulianBle" "grab_cycle_mqttserver" "grab_cycle_mqttserver")

start_p(){
  for key in $(echo ${dic[*]})
  do
    #if [[ $PJT_name == ${key} ]]  && [[ ${key} == "grab_cycle_eureka" ]] && [[ ${HOSTNAME} == "Xgrabcycle-prod-cycle-002" ]];then
    if [ $PJT_name == ${key} -a ${key} == "grab_cycle_eureka"  -a  ${HOSTNAME} == "Xgrabcycle-prod-cycle-002" ];then 
        nohup "/apps/sofe/jdk1.8.0_131/bin/java -jar  -Xms2048M -Xmx4096M -XX:+UseConcMarkSweepGC -XX:-PrintGCDetails -Dspring.profiles.active=prod2  ${key}.jar  >> /apps/project/${key}/${key}.log 2>&1 &"
        sleep 3
        start_pid=`ps -ef | grep "${PJT_DIR}${PJT_name}" | egrep -v "grep"|awk -F'[ ;]+' '{print $2}'`
        echo $start_pid
        if [[ -n $start_pid ]];then
            echo "$PJT_name started is success"
        else
            echo "$PJT_name started is failed"
        fi
    else
        if [[ $PJT_name == "${key}" ]];then
        nohup "/apps/sofe/jdk1.8.0_131/bin/java -jar  -Xms2048M -Xmx4096M -XX:+UseConcMarkSweepGC -XX:-PrintGCDetails -Dspring.profiles.active=prod1  ${key}.jar  >> /apps/project/${key}/${key}.log 2>&1 &"
        sleep 3
        start_pid=`ps -ef | grep "${PJT_DIR}${PJT_name}" | egrep -v "grep" |awk -F'[ ;]+' '{print $2}'`
        echo $start_pid
        if [[ -n $start_pid ]];then
                echo "$PJT_name started is success"
        else
                echo "$PJT_name started is failed"
        fi
        fi
    fi
  done
}

stop_p(){
  for key in $(echo ${dic[*]})
  do
    if [[ $PJT_name == "${key}" ]];then
        pid_number=`ps -ef | grep "${PJT_DIR}${PJT_name}" | egrep -v "grep"|awk -F'[ ;]+' '{print $2}'`
        echo $pid_number
        kill -9 $pid_number
        if [ $? -eq 0 ];then
            echo "$PJT_name shutdown is success"
        else
            echo "$PJT_name shutdown is failed"
        fi
    fi
  done
}

status_p(){
  for key in $(echo ${dic[*]})
  do
    if [[ $PJT_name == "${key}" ]];then
        pid_number=`ps -ef | grep "${PJT_DIR}${PJT_name}" | egrep -v "grep|bash" | awk -F'[ ;]+' '{print $2}'`
        echo $pid_number
        if [[ -n $pid_number ]];then
            echo "$PJT_name  is running"
        else
            echo "$PJT_name  is stoped"
        fi
    fi
  done
}

case "$2" in 
  start)
        start_p
  ;;
  stop)
        stop_p
  ;;
  status)
        status_p
  ;;
  *)
  echo $"Usage: $0 project_name {start|stop|status}"
        exit 2
esac

 

posted @ 2018-08-15 11:15  MR_dy  阅读(1299)  评论(0编辑  收藏  举报