#!/bin/sh

export SERVICE_HOME=/home/cvim/test
export SERVICE_NAME=tsi-comm-server
export SERVICE_VERSION=0.0.1-SNAPSHOT
export EXE_NAME=$SERVICE_NAME-$SERVICE_VERSION.jar
export PID_NAME=$SERVICE_NAME.pid
export SERVICE_PID=$SERVICE_HOME/conf/$PID_NAME

cd $SERVICE_HOME

if [ ! -z "$SERVICE_PID" ]; then
  if [ -f "$SERVICE_PID" ]; then
    kill -15 `cat "$SERVICE_PID"` >/dev/null 2>&1
    echo "$SERVICE_NAME stopping.........."
  else
    echo "$SERVICE_NAME is not running...."
    exit
  fi
fi

LOOP=$(seq 0 9)
for i in $LOOP
do
  sleep 1
  if [ -f "$SERVICE_PID" ]; then
    echo "$SERVICE_NAME stopping.........."
  else
    echo "$SERVICE_NAME stopped.........."
    exit
  fi
done

echo "$SERVICE_NAME cannot be terminated......."
ps -eaf | grep $SERVICE_NAME | grep -v grep
