#!/bin/bash
SERVER=./
APPNAME=javashop
cd $SERVER

start(){
    echo "start service  ..."

    #如果pid文件不存，直接启动
    if [ ! -f  $SERVER$APPNAME.pid ]; then  
    	echo "pid不存在"
    	touch $SERVER$APPNAME.pid
		startone
	else #否则kill掉再启动
		echo "pid存在"
		stopone
		startone
	fi  
   
    
    echo "start service  complete!"
}
 

startone(){
	 nohup java -Xmx512m -Xms256m -Xss256k  -jar javashop-consumer-6.4.0.jar > javashop.out  &
	 echo $! > $SERVER/$APPNAME.pid
}

stopone(){
    echo "stop service  .."
    kill `cat $SERVER/$APPNAME.pid`
    rm -rf $SERVER/$APPNAME.pid   
	sleep 30 #休眠，以免stop需要一些时间
    echo "stop service $APPNAME complete!"
}

start