#!/bin/bash

app_dir=`pwd`
app_name='oss-console.jar'

pid=`ps aux | grep ${app_name} | grep -v 'grep' | tr -s ' '| cut -d ' ' -f 2`
echo "process id: "${pid}
if [[ -z ${pid} ]];
then
  echo "process killed"
else
  kill -15 ${pid}
fi

echo "sleep 10s and wait process killed"
sleep 10
pid=`ps aux | grep ${app_name} | grep -v 'grep' | tr -s ' '| cut -d ' ' -f 2`
if [[ -z ${pid} ]];
then
  echo "${app_name} has killed, restart now"
  nohup java -jar ${app_dir}"/"${app_name} > console.log 2>&1 &
else
  echo "process ${pid} not killed"
fi
