自用的多个jar启动脚本

#!/bin/sh

# 系统模块
MODULES=(collect_ftpschedule collect_ftpservice collect_manager collect_stage_ftpdl collect_stage_parser collect_stage_file2hdfs)
# 系统模块名称
MODULE_NAMES=(任务调度 文件扫描 任务管理 下载 解析 入hdfs)
# jar
JARS=(collect_ftpschedule-1.0-SNAPSHOT.jar collect_ftpservice-1.0-SNAPSHOT.jar collect_manager-1.0-SNAPSHOT.jar collect_stage_ftpdl-1.0-SNAPSHOT.jar collect_stage_parser-1.0-SNAPSHOT.jar collect_stage_file2hdfs-1.0-SNAPSHOT.jar)

# 运行目录,sh当前目录
PWD=$(cd $(dirname $0); pwd)

start() {
  local command="$1"
  local commandOk=0
  local okCount=0
  if [ "$command" == "all" ]
  then
    commandOk=1
    for((i=0;i<${#JARS[@]};i++))
    do
      MODULE=${MODULES[$i]}
      okCount=$(($okCount+1))
      JAR_NAME=${JARS[$i]}
      P_ID=`ps -ef | grep "$JAR_NAME" | grep -v grep | grep -v "$0" | awk '{print $2}'`
      if [ "$P_ID" == "" ]; then
        echo "$MODULE start finished"
        nohup java -Xms256m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=1024m -jar $MODULE/$JAR_NAME >/dev/null 2>&1 &
      else
        echo "$JAR_NAME process is running; pid is:$P_ID; try restart"
      fi
    done
  elif [[ "$command" == "collect_ftpschedule" || "$command" == "collect_ftpservice" || "$command" == "collect_manager" || "$command" == "collect_stage_ftpdl" || "$command" == "collect_stage_parser" || "$command" == "collect_stage_file2hdfs" ]]
  then
    commandOk=1
    okCount=1
    P_ID=`ps -ef | grep "$command" | grep -v grep | grep -v "$0" | awk '{print $2}'`
    if [ "$P_ID" == "" ]; then
      nohup java -Xms256m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=1024m -jar $command/*.jar >/dev/null 2>&1 &
      echo "start $command finished"
    else
      echo "$command process is running; pid is:$P_ID; try restart"
    fi
  fi

  echo "输入命令 ./execute.sh status 查看运行状态"
  if(($commandOk == 0));then
    echo "第二个参数请输入:all|collect_ftpschedule|collect_ftpservice|collect_manager|collect_stage_ftpdl|collect_stage_parser|collect_stage_file2hdfs"
  fi
}

stop() {
  local command="$1"
  local commandOk=0
  local okCount=0
  if [ "$command" == "all" ]
  then
    commandOk=1
    for((i=0;i<${#JARS[@]};i++))
    do
      MODULE=${MODULES[$i]}
      okCount=$(($okCount+1))
      JAR_NAME=${JARS[$i]}
      P_ID=`ps -ef | grep "$JAR_NAME" | grep -v grep | grep -v "$0" | awk '{print $2}'`
      if [ "$P_ID" == "" ]; then
        echo "$MODULE is not running"
      else
        kill -9 $P_ID
        echo "$JAR_NAME process stop finished"
      fi
    done
  elif [[ "$command" == "collect_ftpschedule" || "$command" == "collect_ftpservice" || "$command" == "collect_manager" || "$command" == "collect_stage_ftpdl" || "$command" == "collect_stage_parser" || "$command" == "collect_stage_file2hdfs" ]]
  then
    commandOk=1
    okCount=1
    
    P_ID=`ps -ef | grep "$command" | grep -v grep | grep -v "$0" | awk '{print $2}'`
    if [ "$P_ID" == "" ]; then
      echo "$command process is not running"
    else
      kill -9 $P_ID
      echo "stop $command finished"
    fi
  fi
  echo "输入命令 ./execute.sh status 查看运行状态"

  if(($commandOk == 0));then
    echo "第二个参数请输入:all|collect_ftpschedule|collect_ftpservice|collect_manager|collect_stage_ftpdl|collect_stage_parser|collect_stage_file2hdfs"
  fi
}

#判定服务的运行状态
status() {
  for((i=0;i<${#MODULES[@]};i++))
  do
    MODULE=${MODULES[$i]}
    P_ID=`ps -ef | grep "$MODULE" | grep -v grep | grep -v "$0" | awk '{print $2}'`
    if [ "$P_ID" == "" ]; then
      echo "$MODULE process is not running"
    else
      echo "$MODULE process is running; pid is:$P_ID"
    fi
  done
}

case "$1" in
  start)
    start "$2"
  ;;
  stop)
    stop "$2"
  ;;
  restart)
    stop "$2"
    sleep 1s
    start "$2"
  ;;
  status)
    status
  ;;
  *)
    echo "第一个参数请输入:start|stop|status|restart"
    exit 1
  ;;
esac

目录结构

 

 某个模块的内部:

 这样部署的好处是,只升级核心代码即可。不用每次都修改配置文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早退的程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值