From 44f37dfaff805c325ecdc7efabd8091362025f30 Mon Sep 17 00:00:00 2001 From: Frank Harris Date: Sun, 7 Jun 2026 18:01:52 -0500 Subject: [PATCH] start fix --- .../OGP64/OGP/Install/agent_start.bat | 27 +++++++++- .../OGP64/OGP/Install/agent_start_cygwin.sh | 19 +++++++ docs/agents/WINDOWS_AGENT.md | 50 ++++++++++++++++--- docs/features/INSTALLERS.md | 2 + 4 files changed, 91 insertions(+), 7 deletions(-) diff --git a/Agent-Windows/OGP64/OGP/Install/agent_start.bat b/Agent-Windows/OGP64/OGP/Install/agent_start.bat index fc8a91d7..d30b4ffa 100644 --- a/Agent-Windows/OGP64/OGP/Install/agent_start.bat +++ b/Agent-Windows/OGP64/OGP/Install/agent_start.bat @@ -13,6 +13,7 @@ if not "%errorLevel%" == "0" ( set "WD=%~dp0" pushd "%WD%" >nul 2>&1 +set "START_LOG_NATIVE=" set "BASH_EXE=" set "CYGWIN_ROOT=" @@ -67,9 +68,14 @@ if not exist "%CYGWIN_ROOT%OGP\ogp_agent.pl" ( exit /b 1 ) +set "START_LOG_NATIVE=%CYGWIN_ROOT%var\log\gsp_agent_start.log" +if not exist "%CYGWIN_ROOT%var\log" mkdir "%CYGWIN_ROOT%var\log" >nul 2>&1 + set "PATH=%CYGWIN_ROOT%bin;%CYGWIN_ROOT%usr\sbin;%PATH%" set "CYGWIN=server ntsec" set "SHELL=/bin/bash" +set "GSP_AGENT_START_LOG_NATIVE=%START_LOG_NATIVE%" +set "GSP_AGENT_CYGWIN_ROOT=%CYGWIN_ROOT%" set "HELPER=/Install/agent_start_cygwin.sh" if exist "%CYGWIN_ROOT%OGP\Install\agent_start_cygwin.sh" set "HELPER=/OGP/Install/agent_start_cygwin.sh" @@ -83,6 +89,19 @@ if not exist "%CYGWIN_ROOT%Install\agent_start_cygwin.sh" if not exist "%CYGWIN_ exit /b 1 ) +echo Detected startup paths: +echo Script directory: %WD% +echo Cygwin root: %CYGWIN_ROOT% +echo bash.exe: %BASH_EXE% +echo OGP path: %CYGWIN_ROOT%OGP +echo ogp_agent.pl: %CYGWIN_ROOT%OGP\ogp_agent.pl +echo Config path: %CYGWIN_ROOT%OGP\Cfg +echo Startup log: %START_LOG_NATIVE% +echo. +if exist "%START_LOG_NATIVE%" ( + del /q "%START_LOG_NATIVE%" >nul 2>&1 +) + rem Stop any existing agent processes whose PID files still exist. if exist "%CYGWIN_ROOT%var\run\pure-ftpd.pid" set /p PID1=<"%CYGWIN_ROOT%var\run\pure-ftpd.pid" if exist "%CYGWIN_ROOT%OGP\ogp_agent.pid" set /p PID2=<"%CYGWIN_ROOT%OGP\ogp_agent.pid" @@ -100,7 +119,13 @@ set "AGENT_EXIT=%ERRORLEVEL%" 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. + echo. + echo ===== Last 100 lines of startup log: %START_LOG_NATIVE% ===== + if exist "%START_LOG_NATIVE%" ( + powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-Content -LiteralPath '%START_LOG_NATIVE%' -Tail 100" 2>nul + ) else ( + echo Startup log was not created. + ) call :pause_on_error exit /b %AGENT_EXIT% ) diff --git a/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh b/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh index 020190b1..a0e29490 100644 --- a/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh +++ b/Agent-Windows/OGP64/OGP/Install/agent_start_cygwin.sh @@ -5,6 +5,7 @@ set -u AGENT_DIR="/OGP" PIDFILE="${1:-/OGP/ogp_agent_run.pid}" PREFS_FILE="$AGENT_DIR/Cfg/bash_prefs.cfg" +START_LOG_NATIVE="${GSP_AGENT_START_LOG_NATIVE:-}" REPO_URL_DEFAULT="http://forge.runlevelsystems.com/dev/GSP.git" REPO_BRANCH_DEFAULT="Panel-unstable" RAW_AGENT_URL_DEFAULT="http://forge.runlevelsystems.com/dev/GSP/raw/branch/Panel-unstable/Agent-Windows/OGP64/OGP/ogp_agent.pl" @@ -19,6 +20,23 @@ fail() { exit 1 } +setup_startup_log() { + local default_log="/var/log/gsp_agent_start.log" + local log_path="${default_log}" + + if [ -n "$START_LOG_NATIVE" ] && command -v cygpath >/dev/null 2>&1; then + log_path="$(cygpath -u "$START_LOG_NATIVE" 2>/dev/null || printf '%s' "$default_log")" + elif [ -n "$START_LOG_NATIVE" ]; then + log_path="$START_LOG_NATIVE" + fi + + mkdir -p "$(dirname "$log_path")" 2>/dev/null || true + touch "$log_path" 2>/dev/null || true + exec > >(tee -a "$log_path") 2>&1 + printf 'GSP Windows Agent startup log: %s\n' "$log_path" + printf 'Cygwin root detected by batch: %s\n' "${GSP_AGENT_CYGWIN_ROOT:-unknown}" +} + normalize_text_files() { local root="$1" [ -d "$root" ] || return 0 @@ -211,6 +229,7 @@ auto_update_windows_agent() { cd "$AGENT_DIR" || fail "Could not enter $AGENT_DIR. Is the Windows agent installed under Cygwin /OGP?" +setup_startup_log normalize_text_files "$AGENT_DIR" normalize_text_files "/Install" ensure_default_configs diff --git a/docs/agents/WINDOWS_AGENT.md b/docs/agents/WINDOWS_AGENT.md index d4982fc4..b7249768 100644 --- a/docs/agents/WINDOWS_AGENT.md +++ b/docs/agents/WINDOWS_AGENT.md @@ -68,6 +68,8 @@ This matters because the maintained launcher may be run from `C:\OGP64\agent_sta 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 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 Cygwin-side helper performs the shell work: 1. enter `/OGP` @@ -75,12 +77,14 @@ The Cygwin-side helper performs the shell work: 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. optionally update only the Windows agent file from Forgejo when `agent_auto_update=1` -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. refuse to launch if `Cfg/Config.pm` still contains placeholder values -11. launch `/OGP/ogp_agent.pl` +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` Default optional update source: @@ -94,6 +98,40 @@ Auto-update failure is non-fatal. Missing `curl`/`git`, download failure, clone 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/`. +### 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. + +Manual troubleshooting flow: + +1. Launch `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. + +### Auto-Update Allowlist + +Restart-time auto-update must not touch production config files. Only the following file is allowed to be replaced automatically: + +- `/OGP/ogp_agent.pl` + +It must never overwrite: + +- `Cfg/Config.pm` +- `Cfg/Preferences.pm` +- `Cfg/bash_prefs.cfg` +- service settings +- generated installer config +- server homes +- logs +- user-created files +- passwords or keys + 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. diff --git a/docs/features/INSTALLERS.md b/docs/features/INSTALLERS.md index 0bda64f9..b03bcaa6 100644 --- a/docs/features/INSTALLERS.md +++ b/docs/features/INSTALLERS.md @@ -40,3 +40,5 @@ Common installed layout: 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. + +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.