#!/bin/bash

appname='mjava-zhuogao'

if [ "$1" == "dev" ]; then
  java -Xms256m -Xmx256m -jar $appname.jar --spring.profiles.active=dev
else
  if [ "$1" == "start" ]; then
    nohup java -Xms256m -Xmx256m -jar $appname.jar &
    echo "server prod is starting"
    tail -f log/info.log
  else
    if [ "$1" == "test" ]; then
      nohup java -Xms256m -Xmx256m -jar $appname.jar --spring.profiles.active=test &
      echo "server test is starting"
      tail -f log/info.log
    else
      if [ "$1" == "stop" ]; then
        PID=$(ps -ef | grep $appname.jar | grep -v grep | awk '{ print $2 }')
        if [ -z "$PID" ]; then
          echo "server is already stopped"
        else
          echo kill $PID
          kill $PID
        fi
      else
        if [ "$1" == "status" ]; then
          PID=$(ps -ef | grep $appname.jar | grep -v grep | awk '{ print $2 }')
          if [ -z "$PID" ]; then
            echo "server is stopped"
          else
            echo "server is running"
            echo $PID
          fi
        fi
      fi
    fi
  fi
fi
