#!/bin/bash

# Signal is a parameter that determine the signal sent to kill command defaults to forced
if [ -z "$1" ]; then
    KILL_SIGNAL='-9'
else
    KILL_SIGNAL=$1
fi

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
APP_HOME=$SCRIPT_DIR/..
APP_HOME=$(builtin cd $APP_HOME; pwd)

# Find the PID of the Java process containing APP_HOME in the command line
PID=$(pgrep -f "$APP_HOME/config/application.properties")

if [ -n "$PID" ]; then
    echo "Killing Java process with PID $PID"
    kill $KILL_SIGNAL "$PID"
else
    echo "No Java process found with APP_HOME in the command line"
fi

