From f2dbfe5e4e7f15effcbca3411459ce31bb735a4e Mon Sep 17 00:00:00 2001 From: Frank Harris Date: Sun, 7 Jun 2026 17:21:32 -0500 Subject: [PATCH] agent start fix --- Agent-Windows/OGP64/OGP/Cfg/Config.pm | 13 ---- Agent-Windows/OGP64/OGP/Cfg/Preferences.pm | 9 --- Agent-Windows/OGP64/OGP/Cfg/bash_prefs.cfg | 9 --- .../OGP64/OGP/Install/agent_start.bat | 64 ++++++++++++++----- .../OGP64/OGP/Install/agent_start_cygwin.sh | 31 ++++++--- Agent-Windows/OGP64/OGP/README.md | 4 +- .../OGP64/OGP/documentation/agent-guide.md | 4 +- Agent-Windows/OGP64/agent_start.bat | 6 +- docs/agents/WINDOWS_AGENT.md | 16 ++++- docs/features/INSTALLERS.md | 16 +++++ 10 files changed, 110 insertions(+), 62 deletions(-) delete mode 100644 Agent-Windows/OGP64/OGP/Cfg/Config.pm delete mode 100644 Agent-Windows/OGP64/OGP/Cfg/Preferences.pm delete mode 100644 Agent-Windows/OGP64/OGP/Cfg/bash_prefs.cfg diff --git a/Agent-Windows/OGP64/OGP/Cfg/Config.pm b/Agent-Windows/OGP64/OGP/Cfg/Config.pm deleted file mode 100644 index 214c6603..00000000 --- a/Agent-Windows/OGP64/OGP/Cfg/Config.pm +++ /dev/null @@ -1,13 +0,0 @@ -%Cfg::Config = ( - logfile => '/OGP/ogp_agent.log', - listen_port => '12679', - listen_ip => '0.0.0.0', - version => 'v1.4', - key => 'CHANGE_ME_PANEL_AGENT_KEY', - steam_license => 'Accept', - sudo_password => '', - web_admin_api_key => '', - web_api_url => '', - steam_dl_limit => '0', -); - diff --git a/Agent-Windows/OGP64/OGP/Cfg/Preferences.pm b/Agent-Windows/OGP64/OGP/Cfg/Preferences.pm deleted file mode 100644 index 63b8c169..00000000 --- a/Agent-Windows/OGP64/OGP/Cfg/Preferences.pm +++ /dev/null @@ -1,9 +0,0 @@ -%Cfg::Preferences = ( - screen_log_local => '1', - delete_logs_after => '30', - ogp_manages_ftp => '1', - ftp_method => 'PureFTPd', - ogp_autorestart_server => '1', - protocol_shutdown_waittime => '10', -); - diff --git a/Agent-Windows/OGP64/OGP/Cfg/bash_prefs.cfg b/Agent-Windows/OGP64/OGP/Cfg/bash_prefs.cfg deleted file mode 100644 index 912c6b39..00000000 --- a/Agent-Windows/OGP64/OGP/Cfg/bash_prefs.cfg +++ /dev/null @@ -1,9 +0,0 @@ -agent_auto_update=0 -agent_update_repo_url=http://forge.runlevelsystems.com/dev/GSP.git -agent_update_branch=Panel-unstable -agent_update_raw_url=http://forge.runlevelsystems.com/dev/GSP/raw/branch/Panel-unstable/Agent-Windows/OGP64/OGP/ogp_agent.pl -run_pureftpd=0 -ftp_port=21 -ftp_ip=0.0.0.0 -ftp_pasv_range= - diff --git a/Agent-Windows/OGP64/OGP/Install/agent_start.bat b/Agent-Windows/OGP64/OGP/Install/agent_start.bat index 7c2031a9..fc8a91d7 100644 --- a/Agent-Windows/OGP64/OGP/Install/agent_start.bat +++ b/Agent-Windows/OGP64/OGP/Install/agent_start.bat @@ -7,33 +7,63 @@ if not "%errorLevel%" == "0" ( echo Failure: current permissions are inadequate. echo. echo Run this script with "Run as administrator". - pause + call :pause_on_error exit /b 1 ) set "WD=%~dp0" pushd "%WD%" >nul 2>&1 -set "CYGWIN_ROOT=%WD%" -if not exist "%CYGWIN_ROOT%OGP\ogp_agent.pl" ( - if exist "%WD%..\OGP\ogp_agent.pl" ( - for %%I in ("%WD%..") do set "CYGWIN_ROOT=%%~fI\" - ) -) - set "BASH_EXE=" -if exist "%CYGWIN_ROOT%bin\bash.exe" set "BASH_EXE=%CYGWIN_ROOT%bin\bash.exe" -if not defined BASH_EXE if exist "C:\cygwin64\bin\bash.exe" set "BASH_EXE=C:\cygwin64\bin\bash.exe" -if not defined BASH_EXE if exist "C:\cygwin\bin\bash.exe" set "BASH_EXE=C:\cygwin\bin\bash.exe" +set "CYGWIN_ROOT=" + +if exist "%WD%bin\bash.exe" ( + set "BASH_EXE=%WD%bin\bash.exe" + set "CYGWIN_ROOT=%WD%" +) +if not defined BASH_EXE if exist "%WD%..\bin\bash.exe" ( + set "BASH_EXE=%WD%..\bin\bash.exe" + for %%I in ("%WD%..") do set "CYGWIN_ROOT=%%~fI\" +) +if not defined BASH_EXE if exist "%WD%..\..\bin\bash.exe" ( + set "BASH_EXE=%WD%..\..\bin\bash.exe" + for %%I in ("%WD%..\..") do set "CYGWIN_ROOT=%%~fI\" +) +if not defined BASH_EXE if exist "C:\OGP64\bin\bash.exe" ( + set "BASH_EXE=C:\OGP64\bin\bash.exe" + set "CYGWIN_ROOT=C:\OGP64\" +) +if not defined BASH_EXE if exist "C:\cygwin64\bin\bash.exe" ( + set "BASH_EXE=C:\cygwin64\bin\bash.exe" + set "CYGWIN_ROOT=C:\cygwin64\" +) +if not defined BASH_EXE if exist "C:\cygwin\bin\bash.exe" ( + set "BASH_EXE=C:\cygwin\bin\bash.exe" + set "CYGWIN_ROOT=C:\cygwin\" +) if not defined BASH_EXE ( echo Failure: Cygwin bash.exe was not found. echo. echo Checked: - echo %CYGWIN_ROOT%bin\bash.exe + echo %WD%bin\bash.exe + echo %WD%..\bin\bash.exe + echo %WD%..\..\bin\bash.exe + echo C:\OGP64\bin\bash.exe echo C:\cygwin64\bin\bash.exe echo C:\cygwin\bin\bash.exe - pause + call :pause_on_error + exit /b 1 +) + +if not exist "%CYGWIN_ROOT%OGP\ogp_agent.pl" ( + echo Failure: OGP agent root was not found for detected Cygwin root. + echo. + echo Detected Cygwin root: + echo %CYGWIN_ROOT% + echo Expected agent file: + echo %CYGWIN_ROOT%OGP\ogp_agent.pl + call :pause_on_error exit /b 1 ) @@ -49,7 +79,7 @@ if not exist "%CYGWIN_ROOT%Install\agent_start_cygwin.sh" if not exist "%CYGWIN_ echo Expected one of: echo %CYGWIN_ROOT%Install\agent_start_cygwin.sh echo %CYGWIN_ROOT%OGP\Install\agent_start_cygwin.sh - pause + call :pause_on_error exit /b 1 ) @@ -71,9 +101,13 @@ if not "%AGENT_EXIT%" == "0" ( echo. echo GSP Windows Agent exited with error code %AGENT_EXIT%. echo Review the messages above. The window is staying open so the failure is visible. - pause + call :pause_on_error exit /b %AGENT_EXIT% ) popd >nul 2>&1 exit /b 0 + +:pause_on_error +if /I not "%GSP_AGENT_NO_PAUSE%"=="1" pause +exit /b 0 diff --git a/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh b/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh index 2ac6f9d9..020190b1 100644 --- a/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh +++ b/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh @@ -62,6 +62,15 @@ ensure_default_configs() { normalize_bash_preferences } +validate_required_config() { + if [ ! -f "$AGENT_DIR/Cfg/Config.pm" ]; then + fail "Missing $AGENT_DIR/Cfg/Config.pm. Run agent_conf.sh or copy Config.pm.default and set the Panel agent key." + fi + if grep -Eq "CHANGE_ME_PANEL_AGENT_KEY|key[[:space:]]*=>[[:space:]]*''" "$AGENT_DIR/Cfg/Config.pm"; then + fail "$AGENT_DIR/Cfg/Config.pm still contains placeholder values. Set key/listen settings to match the Panel remote server record." + fi +} + load_agent_preferences() { agent_auto_update=0 agent_update_repo_url="$REPO_URL_DEFAULT" @@ -166,26 +175,31 @@ auto_update_windows_agent() { return 0 fi - if ! validate_agent_file "$target_file"; then + if [ -f "$target_file" ] && ! validate_agent_file "$target_file"; then warn "Current Windows agent does not validate. Auto-update can still replace it if backup succeeds." fi - cp "$target_file" "$backup_file" 2>/dev/null || { - warn "Could not backup $target_file; skipping auto-update." - rm -rf "$tmp_dir" - return 0 - } + if [ -f "$target_file" ]; then + cp "$target_file" "$backup_file" 2>/dev/null || { + warn "Could not backup $target_file; skipping auto-update." + rm -rf "$tmp_dir" + return 0 + } + else + warn "$target_file is missing; installing validated agent without a local backup." + backup_file="" + fi if ! cp "$candidate_file" "$target_file"; then warn "Could not copy updated Windows agent; restoring backup." - cp "$backup_file" "$target_file" 2>/dev/null + [ -n "$backup_file" ] && cp "$backup_file" "$target_file" 2>/dev/null rm -rf "$tmp_dir" return 0 fi if ! validate_agent_file "$target_file"; then warn "Updated Windows agent failed validation after install; restoring backup." - cp "$backup_file" "$target_file" 2>/dev/null + [ -n "$backup_file" ] && cp "$backup_file" "$target_file" 2>/dev/null rm -rf "$tmp_dir" return 0 fi @@ -202,6 +216,7 @@ normalize_text_files "/Install" ensure_default_configs load_agent_preferences auto_update_windows_agent +validate_required_config echo "Validating $AGENT_DIR/ogp_agent.pl..." validate_agent_file "$AGENT_DIR/ogp_agent.pl" || fail "Perl syntax/dependency validation failed. Install missing Cygwin Perl packages or restore a valid Windows agent file." diff --git a/Agent-Windows/OGP64/OGP/README.md b/Agent-Windows/OGP64/OGP/README.md index 7c83fdb1..7337d1d0 100644 --- a/Agent-Windows/OGP64/OGP/README.md +++ b/Agent-Windows/OGP64/OGP/README.md @@ -23,7 +23,7 @@ Cygwin-based agent that lets the GameServer Panel manage Windows Server 2019/202 ## Startup and auto-update -Use `C:\\OGP64\\agent_start.bat` or `C:\\OGP\\Install\\agent_start.bat` to start the agent manually. The launcher detects the bundled Cygwin `bash.exe` first, then falls back to `C:\\cygwin64\\bin\\bash.exe` and `C:\\cygwin\\bin\\bash.exe`. +Use `C:\\OGP64\\agent_start.bat` or `C:\\OGP64\\OGP\\Install\\agent_start.bat` to start the agent manually. The launcher checks the bundled Cygwin root, including `C:\\OGP64\\bin\\bash.exe`, then falls back to `C:\\cygwin64\\bin\\bash.exe` and `C:\\cygwin\\bin\\bash.exe`. Manual failures pause by default; set `GSP_AGENT_NO_PAUSE=1` for service wrappers that should not block. `C:\\OGP\\Cfg\\bash_prefs.cfg` controls optional restart-time agent updates: @@ -34,7 +34,7 @@ agent_update_branch=Panel-unstable agent_update_raw_url=http://forge.runlevelsystems.com/dev/GSP/raw/branch/Panel-unstable/Agent-Windows/OGP64/OGP/ogp_agent.pl ``` -When `agent_auto_update=1`, the launcher downloads to a temporary file, rejects HTML/404/empty/non-Perl content, validates with `perl -c`, backs up the current `ogp_agent.pl`, and rolls back if validation fails. +When `agent_auto_update=1`, the launcher downloads to a temporary file, rejects HTML/404/empty/non-Perl content, validates with `perl -c`, backs up the current `ogp_agent.pl`, and rolls back if validation fails. This restart-time updater may replace only `/OGP/ogp_agent.pl`; it must not touch `Cfg/` files or other installer-generated state. ## Related repositories diff --git a/Agent-Windows/OGP64/OGP/documentation/agent-guide.md b/Agent-Windows/OGP64/OGP/documentation/agent-guide.md index d7db71fd..1c5f2fee 100644 --- a/Agent-Windows/OGP64/OGP/documentation/agent-guide.md +++ b/Agent-Windows/OGP64/OGP/documentation/agent-guide.md @@ -49,9 +49,9 @@ Restart-time auto-update: agent_update_branch=Panel-unstable agent_update_raw_url=http://forge.runlevelsystems.com/dev/GSP/raw/branch/Panel-unstable/Agent-Windows/OGP64/OGP/ogp_agent.pl ``` -4. Restart the agent with `C:\\OGP64\\agent_start.bat` or `C:\\OGP\\Install\\agent_start.bat`. +4. Restart the agent with `C:\\OGP64\\agent_start.bat` or `C:\\OGP64\\OGP\\Install\\agent_start.bat`. -The updater downloads to a temporary file, rejects empty files, HTML error pages, `Not found` responses, and files without the expected Perl agent markers, then runs `perl -c` before replacing `/OGP/ogp_agent.pl`. Failed auto-update attempts are non-fatal and continue with the last known good agent. +The updater downloads to a temporary file, rejects empty files, HTML error pages, `Not found` responses, and files without the expected Perl agent markers, then runs `perl -c` before replacing `/OGP/ogp_agent.pl`. Failed auto-update attempts are non-fatal and continue with the last known good agent. The restart-time updater is allowlisted to `/OGP/ogp_agent.pl` only and must not overwrite `/OGP/Cfg/*`, service settings, passwords, server data, or logs. ## Logging & troubleshooting diff --git a/Agent-Windows/OGP64/agent_start.bat b/Agent-Windows/OGP64/agent_start.bat index cc6dd3f1..192867ca 100644 --- a/Agent-Windows/OGP64/agent_start.bat +++ b/Agent-Windows/OGP64/agent_start.bat @@ -12,9 +12,13 @@ if not exist "%INNER_START%" ( echo %INNER_START% echo. echo This checkout should contain OGP\Install\agent_start.bat. - pause + call :pause_on_error exit /b 1 ) call "%INNER_START%" exit /b %ERRORLEVEL% + +:pause_on_error +if /I not "%GSP_AGENT_NO_PAUSE%"=="1" pause +exit /b 0 diff --git a/docs/agents/WINDOWS_AGENT.md b/docs/agents/WINDOWS_AGENT.md index 0989ee13..d4982fc4 100644 --- a/docs/agents/WINDOWS_AGENT.md +++ b/docs/agents/WINDOWS_AGENT.md @@ -57,10 +57,17 @@ Relevant files: The batch launcher must not assume that `bash` is in the Windows `PATH`. It explicitly checks: -- the Cygwin root beside the launcher +- `%~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. + +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. + The Cygwin-side helper performs the shell work: 1. enter `/OGP` @@ -72,7 +79,8 @@ The Cygwin-side helper performs the shell work: 7. backup the current `/OGP/ogp_agent.pl` 8. validate downloaded and installed agent files with content checks plus `perl -c` 9. restore the backup if validation fails -10. launch `/OGP/ogp_agent.pl` +10. refuse to launch if `Cfg/Config.pm` still contains placeholder values +11. launch `/OGP/ogp_agent.pl` Default optional update source: @@ -84,11 +92,13 @@ Default optional update source: Auto-update failure is non-fatal. Missing `curl`/`git`, download failure, clone failure, missing source file, HTTP error-page downloads, empty files, or failed validation should warn and continue with the current installed agent. +Restart-time auto-update is allowlisted. It may replace only `/OGP/ogp_agent.pl`. It must never overwrite `Cfg/Config.pm`, `Cfg/Preferences.pm`, `Cfg/bash_prefs.cfg`, service settings, passwords, generated installer config, server homes, logs, or user-created files. Broader agent updates belong to the admin-only Panel `component_update` flow, which also preserves `Cfg/`. + 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. -Default tracked config files contain placeholders only. Production installs must replace `CHANGE_ME_PANEL_AGENT_KEY`, `web_api_url`, and related values with the values configured in the Panel remote-server record. +Default tracked config template files contain placeholders only. Production installs must replace `CHANGE_ME_PANEL_AGENT_KEY`, `web_api_url`, and related values with the values configured in the Panel remote-server record. If startup creates `Config.pm` from `Config.pm.default`, it stops with a clear error until those values are changed. ## Status Logic diff --git a/docs/features/INSTALLERS.md b/docs/features/INSTALLERS.md index d0dcd9dc..0bda64f9 100644 --- a/docs/features/INSTALLERS.md +++ b/docs/features/INSTALLERS.md @@ -24,3 +24,19 @@ Important references: ## Recommended Model Installer strategy should come from game capability metadata. The agent should execute trusted strategies, not arbitrary customer commands. + +## Windows Agent Install Notes + +The Windows agent is Cygwin-based under `Agent-Windows/OGP64`. + +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` + +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. + +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.