This commit is contained in:
Frank Harris 2026-06-07 18:51:56 -05:00
parent 44f37dfaff
commit 8f5ad2984a
5 changed files with 106 additions and 73 deletions

View file

@ -1,24 +1,68 @@
@echo off
setlocal EnableExtensions
title GSP Windows Agent
setlocal
set "ROOT=%~dp0"
set "INNER_START=%ROOT%OGP\Install\agent_start.bat"
REM GSP / OGP Windows Agent start script
REM Cygwin root is the folder containing this BAT file, usually C:\OGP64
if not exist "%INNER_START%" (
echo Failure: maintained agent launcher was not found.
echo.
echo Expected:
echo %INNER_START%
echo.
echo This checkout should contain OGP\Install\agent_start.bat.
call :pause_on_error
exit /b 1
set "WD=%~dp0"
pushd "%WD%"
set "PATH=%WD%bin;%WD%usr\sbin;%PATH%"
set "CYGWIN=server ntsec"
set "SHELL=/bin/bash"
set "AGENT_USER=gameserver"
echo Starting GSP Windows Agent...
echo Cygwin root: %WD%
echo Agent user: %AGENT_USER%
if not exist "%WD%bin\bash.exe" (
echo ERROR: bash.exe not found at "%WD%bin\bash.exe"
echo This script must be run from the Cygwin root folder, for example C:\OGP64
pause
exit /b 1
)
call "%INNER_START%"
exit /b %ERRORLEVEL%
if not exist "%WD%OGP\ogp_agent.pl" (
echo ERROR: "%WD%OGP\ogp_agent.pl" not found.
pause
exit /b 1
)
:pause_on_error
if /I not "%GSP_AGENT_NO_PAUSE%"=="1" pause
exit /b 0
REM Verify gameserver user exists
net user %AGENT_USER%
if errorlevel 1 (
echo ERROR: Windows user "%AGENT_USER%" was not found.
echo Create the gameserver user or update AGENT_USER in this script.
pause
exit /b 1
)
REM Normalize line endings for known text files only
"%WD%bin\bash.exe" -lc "cd /OGP && find . -type f \( -name '*.pl' -o -name '*.pm' -o -name '*.sh' -o -name '*.cfg' \) -exec sed -i 's/\r$//' {} \;"
REM Validate Perl before starting
"%WD%bin\bash.exe" -lc "cd /OGP && perl -c ./ogp_agent.pl"
if errorlevel 1 (
echo ERROR: ogp_agent.pl failed Perl validation.
pause
exit /b 1
)
REM Stop stale PID processes if present
if exist "%WD%var\run\pure-ftpd.pid" set /p PID1=<"%WD%var\run\pure-ftpd.pid"
if exist "%WD%OGP\ogp_agent.pid" set /p PID2=<"%WD%OGP\ogp_agent.pid"
if exist "%WD%OGP\ogp_agent_run.pid" set /p PID3=<"%WD%OGP\ogp_agent_run.pid"
if not "%PID1%"=="" "%WD%bin\kill.exe" -15 %PID1%
if not "%PID2%"=="" "%WD%bin\kill.exe" -15 %PID2%
if not "%PID3%"=="" "%WD%bin\kill.exe" -15 %PID3%
echo Launching agent...
"%WD%bin\bash.exe" -lc "cd /OGP && ./ogp_agent.pl -pidfile /OGP/ogp_agent_run.pid"
echo.
echo GSP Windows Agent exited with error code %ERRORLEVEL%.
echo Review the messages above.
pause
exit /b %ERRORLEVEL%