last fix
This commit is contained in:
parent
44f37dfaff
commit
8f5ad2984a
5 changed files with 106 additions and 73 deletions
|
|
@ -91,7 +91,7 @@ use constant FD_PID_FILE => Path::Class::File->new(FD_DIR, 'fd.pid');
|
|||
use constant SCHED_PID => Path::Class::File->new(AGENT_RUN_DIR, 'scheduler.pid');
|
||||
use constant SCHED_TASKS => Path::Class::File->new(AGENT_RUN_DIR, 'scheduler.tasks');
|
||||
use constant SCHED_LOG_FILE => Path::Class::File->new(AGENT_RUN_DIR, 'scheduler.log');
|
||||
use constant USER_RUNNING_SCRIPT => getlogin || getpwuid($<) || "cyg_server";
|
||||
use constant USER_RUNNING_SCRIPT => getlogin || getpwuid($<) || "gameserver";
|
||||
|
||||
my $no_startups = 0;
|
||||
my $clear_startups = 0;
|
||||
|
|
|
|||
|
|
@ -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%
|
||||
|
|
|
|||
|
|
@ -1,24 +1,20 @@
|
|||
@echo off
|
||||
@title Stop OGP Agent
|
||||
net session >nul 2>&1
|
||||
if NOT %errorLevel% == 0 (
|
||||
echo Failure: Current permissions inadequate.
|
||||
echo[
|
||||
echo Run this script by using "Run as administrator" in the context menu.
|
||||
pause >nul
|
||||
exit
|
||||
)
|
||||
set WD=%~dp0
|
||||
pushd %WD%
|
||||
set path=%WD%bin;%WD%usr\sbin;%path%
|
||||
set CYGWIN=server ntsec
|
||||
set SHELL=/bin/bash
|
||||
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 exist %WD%OGP\scheduler.pid set /p PID4=<%WD%OGP\scheduler.pid
|
||||
IF NOT [%PID1%] == [] kill -15 %PID1%
|
||||
IF NOT [%PID2%] == [] kill -15 %PID2%
|
||||
IF NOT [%PID3%] == [] kill -15 %PID3%
|
||||
IF NOT [%PID4%] == [] kill -15 %PID4%
|
||||
taskkill /IM perl.exe /F
|
||||
setlocal
|
||||
|
||||
set "WD=%~dp0"
|
||||
pushd "%WD%"
|
||||
|
||||
set "PATH=%WD%bin;%WD%usr\sbin;%PATH%"
|
||||
|
||||
echo Stopping GSP Windows Agent...
|
||||
|
||||
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 Done.
|
||||
pause
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@
|
|||
- `Agent-Windows/OGP64/OGP/Cfg/Preferences.pm`
|
||||
- `Agent-Windows/OGP64/OGP/Cfg/bash_prefs.cfg`
|
||||
- `Agent-Windows/OGP64/OGP/Cfg/*.default`
|
||||
- `Agent-Windows/OGP64/agent_start.bat`
|
||||
- `Agent-Windows/OGP64/agent_stop.bat`
|
||||
- `Agent-Windows/php-query/`
|
||||
- `Agent-Windows/ArmaBE/`
|
||||
- `Agent-Windows/Cfg/`
|
||||
- `Agent-Windows/Install/`
|
||||
- `Agent-Windows/ServerFiles/`
|
||||
- `Agent-Windows/Schedule/`
|
||||
|
||||
|
|
@ -51,40 +52,33 @@ OGP_HOME_000000123
|
|||
|
||||
Relevant files:
|
||||
|
||||
- `Agent-Windows/Install/agent_start.bat`
|
||||
- `Agent-Windows/Install/agent_start_cygwin.sh`
|
||||
- `Agent-Windows/OGP64/agent_start.bat`
|
||||
- `Agent-Windows/OGP64/agent_stop.bat`
|
||||
- `/OGP/Cfg/bash_prefs.cfg` on an installed node
|
||||
|
||||
The batch launcher must not assume that `bash` is in the Windows `PATH`. It explicitly checks:
|
||||
|
||||
- `%~dp0bin\bash.exe`
|
||||
- `%~dp0..\bin\bash.exe`
|
||||
- `%~dp0..\..\bin\bash.exe`
|
||||
- `C:\OGP64\bin\bash.exe`
|
||||
- `C:\cygwin64\bin\bash.exe`
|
||||
- `C:\cygwin\bin\bash.exe`
|
||||
|
||||
This matters because the maintained launcher may be run from `C:\OGP64\agent_start.bat` or from `C:\OGP64\OGP\Install\agent_start.bat`. In the second case the actual Cygwin root is two directories above the launcher, so `C:\OGP64\bin\bash.exe` must be checked.
|
||||
The supported manual launcher is `C:\OGP64\agent_start.bat`. The Cygwin root is the folder containing that BAT file, so the path checks stay simple and deterministic.
|
||||
|
||||
Manual launches pause on fatal errors so the error remains visible. Service or scheduled-task wrappers can set `GSP_AGENT_NO_PAUSE=1` to return immediately instead of waiting forever at a `pause` prompt.
|
||||
Manual launches pause on fatal errors so the error remains visible.
|
||||
|
||||
The launcher now prints the detected script directory, Cygwin root, `bash.exe` path, OGP path, `ogp_agent.pl` path, config path, and startup log path before it launches the shell helper. The goal is to keep the original failure visible in the same console window instead of replacing it with a generic wrapper message.
|
||||
The launcher prints the detected Cygwin root and agent user before validation, then keeps all startup output in the same console window. It does not spawn a second generic wrapper window.
|
||||
|
||||
The Cygwin-side helper performs the shell work:
|
||||
The BAT launcher performs the shell work directly:
|
||||
|
||||
1. enter `/OGP`
|
||||
2. normalize CRLF to LF for `.pl`, `.pm`, `.sh`, and `.cfg` files under `/OGP`
|
||||
3. create missing `Cfg/Config.pm`, `Cfg/Preferences.pm`, and `Cfg/bash_prefs.cfg` from tracked `.default` files
|
||||
4. strip CRLF and leading whitespace before assignments in `/OGP/Cfg/bash_prefs.cfg`
|
||||
5. source `/OGP/Cfg/bash_prefs.cfg`
|
||||
6. set up `gsp_agent_start.log` under `/var/log` by default, or the native `C:\OGP64\var\log\gsp_agent_start.log` path when passed from the batch wrapper
|
||||
7. tee stdout and stderr to the startup log while still printing live output in the same console
|
||||
8. optionally update only the Windows agent file from Forgejo when `agent_auto_update=1`
|
||||
9. backup the current `/OGP/ogp_agent.pl`
|
||||
10. validate downloaded and installed agent files with content checks plus `perl -c`
|
||||
11. restore the backup if validation fails
|
||||
12. refuse to launch if `Cfg/Config.pm` still contains placeholder values
|
||||
13. launch `/OGP/ogp_agent.pl`
|
||||
6. verify the Windows account `gameserver` exists
|
||||
7. run `perl -c ./ogp_agent.pl` before launch
|
||||
8. launch `/OGP/ogp_agent.pl`
|
||||
|
||||
Default optional update source:
|
||||
|
||||
|
|
@ -100,19 +94,14 @@ Restart-time auto-update is allowlisted. It may replace only `/OGP/ogp_agent.pl`
|
|||
|
||||
### Startup Log And Troubleshooting
|
||||
|
||||
Default startup log:
|
||||
|
||||
- `/var/log/gsp_agent_start.log` inside Cygwin
|
||||
- `C:\OGP64\var\log\gsp_agent_start.log` when launched through the Windows batch wrapper
|
||||
|
||||
If startup fails, the batch wrapper prints the last 100 lines of that log in the same console window before pausing. This is the primary place to look for the real cause of a bad config, missing package, or bad downloaded agent file.
|
||||
The launcher does not create a separate startup wrapper window. If startup fails, the real Perl or config error remains in the same console window before the pause prompt. This is the primary place to look for a bad config, missing package, or bad downloaded agent file.
|
||||
|
||||
Manual troubleshooting flow:
|
||||
|
||||
1. Launch `agent_start.bat` directly from the Windows console or Explorer.
|
||||
1. Launch `C:\OGP64\agent_start.bat` directly from the Windows console or Explorer.
|
||||
2. Read the path summary printed at the top of the window.
|
||||
3. Check the log tail printed on failure.
|
||||
4. Inspect `gsp_agent_start.log` for the full startup sequence.
|
||||
3. Inspect the same window for the real Perl/config error.
|
||||
4. Check the current Cygwin output if you need more context.
|
||||
|
||||
### Auto-Update Allowlist
|
||||
|
||||
|
|
@ -132,6 +121,10 @@ It must never overwrite:
|
|||
- user-created files
|
||||
- passwords or keys
|
||||
|
||||
### Windows User Account
|
||||
|
||||
The Windows/Cygwin startup path uses the `gameserver` user account. It does not reference `cyg_server` in the agent start logic. The installer and service bootstrap flow should create or verify `gameserver` before the agent is launched.
|
||||
|
||||
The Windows agent file does not use `DBI` at startup. If a Windows node reports `Can't locate DBI.pm` at line 48, it is a strong signal that a Linux agent file was copied onto the Windows node.
|
||||
|
||||
Required Cygwin Perl packages include `perl`, `perl_vendor`, `perl-HTTP-Daemon`, `perl-Path-Class`, `perl-XML-Parser`, `perl-XML-Simple`, `perl-Archive-Zip`, and `perl-Archive-Extract`. A clean non-Cygwin Linux workstation may fail `perl -c` on these dependencies even though the bundled Windows Cygwin tree contains them.
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ Common installed layout:
|
|||
- Cygwin root: `C:\OGP64`
|
||||
- Bash: `C:\OGP64\bin\bash.exe`
|
||||
- Agent root: `C:\OGP64\OGP`
|
||||
- Maintained launcher: `C:\OGP64\OGP\Install\agent_start.bat`
|
||||
- Convenience launcher: `C:\OGP64\agent_start.bat`
|
||||
- Maintained launcher: `C:\OGP64\agent_start.bat`
|
||||
- Stop launcher: `C:\OGP64\agent_stop.bat`
|
||||
|
||||
The launcher checks `%~dp0bin\bash.exe`, `%~dp0..\bin\bash.exe`, `%~dp0..\..\bin\bash.exe`, `C:\OGP64\bin\bash.exe`, `C:\cygwin64\bin\bash.exe`, and `C:\cygwin\bin\bash.exe`. Missing-bash errors should print every checked path and pause in manual use. Set `GSP_AGENT_NO_PAUSE=1` for service/non-interactive wrappers that should fail fast instead of waiting at a prompt.
|
||||
The launcher checks `%~dp0bin\bash.exe`, `C:\OGP64\bin\bash.exe`, `C:\cygwin64\bin\bash.exe`, and `C:\cygwin\bin\bash.exe`. Missing-bash errors should print every checked path and pause in manual use.
|
||||
|
||||
Generated config files under `/OGP/Cfg` are production state. Installer/startup may create them from `.default` templates if missing, but update logic must preserve them. Restart-time auto-update may replace only `/OGP/ogp_agent.pl`; it must not overwrite `Cfg/Config.pm`, `Cfg/Preferences.pm`, `Cfg/bash_prefs.cfg`, service settings, passwords, server data, or logs.
|
||||
|
||||
When the Windows agent starts, the batch wrapper now writes the startup log to `C:\OGP64\var\log\gsp_agent_start.log` when that Cygwin root is detected, and the Cygwin helper tees live output to `/var/log/gsp_agent_start.log` inside the shell environment. Manual failures print the last 100 lines of that log before the console pauses, so the original error remains visible in the same window.
|
||||
When the Windows agent starts, `C:\OGP64\agent_start.bat` should be launched from the Cygwin root itself. It verifies the `gameserver` account, normalizes text files, validates `OGP\ogp_agent.pl`, and then launches the agent in the same console window. It should not call an installer wrapper from the start script.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue