#!/bin/sh
export GATEWAY=/home/SpaceObj/spaceobj-gateway-1.0.jar
export SYSTEM=/home/SpaceObj/spaceobj-system-1.0.jar
export GATEWAY_log=/home/SpaceObj/logs/gateway.log
export SYSTEM_log=/home/SpaceObj/logs/system.log
export GATEWAY_port=8081
export SYSTEM_port=8088
case "$1" in
start)
# 启动 GATEWAY
echo "--------GATEWAY 开始启动--------------"
nohup java -jar $GATEWAY > $GATEWAY_log 2>&1 &
GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$GATEWAY_pid" ]
do
GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'`
done
echo "GATEWAY pid is $GATEWAY_pid"
sleep 2
echo "--------GATEWAY 启动成功--------------"
# 启动 SYSTEM
echo "--------SYSTEM 开始启动--------------"
nohup java -jar -Xmx2g -Xms2g -jar $SYSTEM > $SYSTEM_log 2>&1 &
SYSTEM_pid=`lsof -i:$SYSTEM_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$SYSTEM_pid" ]
do
SYSTEM_pid=`lsof -i:$SYSTEM_port|grep "LISTEN"|awk '{print $2}'`
done
echo "SYSTEM pid is $SYSTEM_pid"
sleep 2
echo "--------SYSTEM 启动成功--------------"
echo "===all app start success==="
;;
stop)
P_ID=`ps -ef | grep -w $GATEWAY | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===GATEWAY process not exists or stop success"
else
kill -9 $P_ID
echo "GATEWAY killed success"
fi
P_ID=`ps -ef | grep -w $SYSTEM | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===SYSTEM process not exists or stop success"
else
kill -9 $P_ID
echo "SYSTEM killed success"
fi
echo "===stop success==="
;;
restart)
$0 stop
sleep 10
$0 start
echo "===restart success==="
;;
esac
exit 0