@echo off
setlocal

set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%..") do set "APP_HOME=%%~fI"

set "PID_FILE=%APP_HOME%\run\server.pid"

if not exist "%PID_FILE%" (
    echo Castara is not running.
    exit /b 0
)

set /p SERVER_PID=<"%PID_FILE%"
del "%PID_FILE%" >nul 2>&1

if "%SERVER_PID%"=="" (
    echo Castara is not running.
    exit /b 0
)

taskkill /PID %SERVER_PID% /T /F >nul 2>&1
if errorlevel 1 (
    echo Castara is not running.
) else (
    echo Castara stopped.
)

endlocal