#!/bin/sh
export EUREKA=./zatx_eureka.jar
export ZATX_MODEL=./zatx_model.jar
export MONITOR=./zatx_monitor.jar
export EUREKA_port=8761
export ZATX_MODEL_port=1314
export MONITOR_port=8769
case "$1" in
start)
## 启动eureka
echo "--------eureka 开始启动--------------"
nohup java -jar $EUREKA >/dev/null 2>&1 &
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 启动成功--------------"
## 启动ZATX_MODEL
echo "--------开始启动ZATX_MODEL---------------"
nohup java -jar $ZATX_MODEL >/dev/null 2>&1 &
ZATX_MODEL_pid=`lsof -i:$ZATX_MODEL_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$ZATX_MODEL_pid" ]
do
ZATX_MODEL_pid=`lsof -i:$ZATX_MODEL_port|grep "LISTEN"|awk '{print $2}'`
done
echo "ZATX_MODEL pid is $ZATX_MODEL_pid"
echo "---------ZATX_MODEL 启动成功-----------"
## 启动MONITOR
echo "--------开始启动MONITOR---------------"
nohup java -jar $MONITOR >/dev/null 2>&1 &
MONITOR_pid=`lsof -i:$MONITOR_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$MONITOR_pid" ]
do
MONITOR_pid=`lsof -i:$MONITOR_port|grep "LISTEN"|awk '{print $2}'`
done
echo "MONITOR pid is $MONITOR_pid"
echo "---------MONITOR 启动成功-----------"
;;
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 $ZATX_MODEL | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===ZATX_MODEL process not exists or stop success"
else
kill -9 $P_ID
echo "ZATX_MODEL killed success"
fi
P_ID=`ps -ef | grep -w $MONITOR | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===MONITOR process not exists or stop success"
else
kill -9 $P_ID
echo "MONITOR killed success"
fi
echo "===stop success==="
;;
restart)
$0 stop
sleep 2
$0 start
echo "===restart success==="
;;
esac
exit 0
lsof 命令没有的话得安装
yum install lsof
修改对应的地方即可