#!/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
目录结构

某个模块的内部:

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

1万+

被折叠的 条评论
为什么被折叠?



