From f3630f63ba9f9ca32c41eb3e8b4a6f87e47750a2 Mon Sep 17 00:00:00 2001
From: Mikei386 <44135113+Mikei386@users.noreply.github.com>
Date: Sat, 17 Oct 2026 15:43:14 +0200
Subject: [PATCH] Run Hermes gateway with WebUI through persistent lifecycle
wrapper
---
.../webui/CLEAN-INSTALL-2026-10-17.md | 4 +
.../OWN-INSTANCE-MEDIA-MCP-2026-10-17.md | 6 ++
integrations/hermes-unraid/webui/README.md | 2 +
.../SINGLE-CONTAINER-GATEWAY-2026-10-17.md | 91 +++++++++++++++++++
.../webui/my-Hermes-Agent-Web-UI.xml | 9 +-
...ingle-container-acceptance-2026-10-17.json | 31 +++++++
.../hermes-unraid/webui/start-with-gateway.sh | 77 ++++++++++++++++
7 files changed, 216 insertions(+), 4 deletions(-)
create mode 100644 integrations/hermes-unraid/webui/SINGLE-CONTAINER-GATEWAY-2026-10-17.md
create mode 100644 integrations/hermes-unraid/webui/single-container-acceptance-2026-10-17.json
create mode 100644 integrations/hermes-unraid/webui/start-with-gateway.sh
diff --git a/integrations/hermes-unraid/webui/CLEAN-INSTALL-2026-10-17.md b/integrations/hermes-unraid/webui/CLEAN-INSTALL-2026-10-17.md
index 907505e..cf9733c 100644
--- a/integrations/hermes-unraid/webui/CLEAN-INSTALL-2026-10-17.md
+++ b/integrations/hermes-unraid/webui/CLEAN-INSTALL-2026-10-17.md
@@ -1,6 +1,10 @@
# Independent Hermes WebUI — clean installation, 17 October 2026
This supersedes the earlier shared-source native test described in README.md.
+The later [single-container gateway integration](SINGLE-CONTAINER-GATEWAY-2026-10-17.md)
+supersedes only the startup/mount details below: it adds a persistent read-only
+startup script and a gateway process in this same container. The original clean
+data isolation and workspace layout remain intact.
At the user's explicit request, `Hermes-Agent-Web-UI` was stopped and removed,
and its entire `/mnt/nvme-storage/appdata/Hermes-Agent-Web-UI` directory deleted.
diff --git a/integrations/hermes-unraid/webui/OWN-INSTANCE-MEDIA-MCP-2026-10-17.md b/integrations/hermes-unraid/webui/OWN-INSTANCE-MEDIA-MCP-2026-10-17.md
index 1d7e3d5..aa8519a 100644
--- a/integrations/hermes-unraid/webui/OWN-INSTANCE-MEDIA-MCP-2026-10-17.md
+++ b/integrations/hermes-unraid/webui/OWN-INSTANCE-MEDIA-MCP-2026-10-17.md
@@ -3,6 +3,12 @@
Following the clean rebuild, the user explicitly requested restoring MCPs,
image generation, STT and TTS into the independent instance only.
+Later on the same date, the user approved a persistent startup wrapper for a
+gateway process in this same container. See
+[single-container scheduling](SINGLE-CONTAINER-GATEWAY-2026-10-17.md).
+That supersedes the scheduler gap and the two-mount inventory below; an extra
+read-only startup-script mount is now present. Media limitations remain unchanged.
+
## Data separation
The 20 MCP definitions were read once from the stopped old Agent's config and
diff --git a/integrations/hermes-unraid/webui/README.md b/integrations/hermes-unraid/webui/README.md
index 6576ac0..ca718ac 100644
--- a/integrations/hermes-unraid/webui/README.md
+++ b/integrations/hermes-unraid/webui/README.md
@@ -3,6 +3,8 @@
**Current deployment, 2026-10-17:** `Hermes-Agent-Web-UI` was deleted with its
own appdata and rebuilt independently. Only the Webtop workspace is shared.
See the [clean installation and restore recipe](CLEAN-INSTALL-2026-10-17.md).
+The subsequently approved [single-container gateway startup](SINGLE-CONTAINER-GATEWAY-2026-10-17.md)
+adds scheduled background execution without a second container.
The sections below record earlier states; their shared agent-source mounts and
copied chat/skill state no longer describe the active installation.
diff --git a/integrations/hermes-unraid/webui/SINGLE-CONTAINER-GATEWAY-2026-10-17.md b/integrations/hermes-unraid/webui/SINGLE-CONTAINER-GATEWAY-2026-10-17.md
new file mode 100644
index 0000000..45bb5b4
--- /dev/null
+++ b/integrations/hermes-unraid/webui/SINGLE-CONTAINER-GATEWAY-2026-10-17.md
@@ -0,0 +1,91 @@
+# WebUI and scheduled jobs in one container
+
+User-authorized operator integration, 17 October 2026. This supersedes the
+single-process lifecycle in CLEAN-INSTALL-2026-10-17.md; its data isolation,
+provider, MCP, media and workspace settings remain applicable.
+
+## Boundary with upstream
+
+The upstream Docker guide explicitly permits `hermes gateway` as a long-lived
+background process in the WebUI container, but recommends separate containers.
+It does not provide a complete joint-startup script. Our only application-level
+integration is [start-with-gateway.sh](start-with-gateway.sh); neither upstream
+program nor the image initializer is patched, and no custom image is built.
+
+References:
+- https://github.com/nesquena/hermes-webui/blob/master/docs/docker.md#scheduled-jobs-and-the-gateway-daemon
+- https://github.com/nesquena/hermes-webui/blob/master/docs/supervisor.md
+
+## Persistent deployment
+
+- Container: `Hermes-Agent-Web-UI`; WebUI stays on LAN port 8787.
+- Existing official image retained during this change, image ID
+ `sha256:69c20f7dee287c68051b3a7a33d7184cc12498d20ad0d0c9dd4acc36a82edba8`.
+- Command: `/bin/bash /opt/hermes-start/start-with-gateway.sh`.
+- Existing own home and Webtop `/config` mounts retained.
+- Added read-only file mount:
+ `/mnt/nvme-storage/appdata/Hermes-Agent-Web-UI/deployment/start-with-gateway.sh`
+ to `/opt/hermes-start/start-with-gateway.sh`.
+- `restart=unless-stopped`, stop timeout 35 seconds; existing CPU/RAM limits retained.
+- Both runtime processes use UID/GID 1000 and the same `HERMES_HOME`.
+- Old `Hermes-Agent` and `Hermes-WebUI` remain stopped and separate.
+
+The wrapper starts the unmodified `/hermeswebui_init.bash`, waits for WebUI
+readiness and the installed CLI, then starts `hermes gateway run
+--external-supervisor` as the unprivileged WebUI user. A service exit ends the
+whole unit; Docker restarts it. Shutdown signals all descendant service process
+groups (including sessions created by the upstream `su`) and bounds shutdown.
+
+The gateway API binds only to container loopback on port 8642, with a generated
+authentication key. `HERMES_API_URL` points the WebUI health probe there; it does
+not select gateway chat. Chats continue using the native in-process backend,
+retaining its context/reasoning/tool UI behavior. No gateway port is published.
+Secrets live only in the existing root-only `private/runtime.env`, never here.
+
+The Unraid template includes the command, script mount and env-file, so an Apply
+or image recreation retains this layout. Docker restart policy provides process
+recovery and daemon-start recovery unless the operator intentionally stopped it.
+An update that changes upstream initialization or CLI semantics needs retesting.
+
+## Restore and updates
+
+Private encrypted backup must include the own Hermes home, `private/runtime.env`,
+deployment script and Unraid template, plus the existing Webtop home. The script
+also lives in Git. Recreate from the XML after restoring those files. Runtime
+dependencies regenerate through upstream initialization; the existing private
+Hermes source checkout remains its input. No named source volume or dependency
+on the old Agent is introduced. This optional Docker integration is not a native
+Athena full-system restore drill.
+
+The two-container Compose binary and public template downloaded during the
+earlier investigation were removed; no Compose stack or second container was
+created. They are not required for operation.
+
+## Acceptance
+
+Verified through the running official APIs and browser:
+
+- WebUI health OK, zero active runs before the planned restart.
+- Gateway loopback health and detailed health OK.
+- Authenticated WebUI reports gateway configured and running.
+- The browser Tasks panel no longer displays the gateway-not-configured banner.
+- A one-shot synthetic `--no-agent` script job was created with the official CLI,
+ then the container was restarted before it was due. The gateway automatically
+ dispatched it afterwards; its marker matched and its stored status was `ok`,
+ completed 1/1. No manual tick/Run-now call was used. The test job was removed.
+- All 20 existing MCP definitions remain configured; terminal backend remains SSH.
+- No second Hermes container was started.
+- A targeted gateway termination while WebUI and gateway were idle caused the
+ wrapper to exit and Docker to restart the container automatically; the Docker
+ restart counter increased from 0 to 1. The first failure-injection test exposed
+ the image's missing `ps` command; the wrapper was corrected to use only Bash
+ and `/proc` for descendant groups, with no new packages, and the test repeated.
+- After that automatic restart, both health endpoints returned OK again. Browser
+ Tasks displayed no gateway warning and no leftover test task. Screenshot:
+ `/private/tmp/hermes-single-container-scheduler-20261017.png`.
+
+This scheduler check tests automatic dispatch, not a newly evaluated AI answer
+or every MCP operation. Existing media acceptance remains a separate test.
+Existing media limitations in OWN-INSTANCE-MEDIA-MCP-2026-10-17.md remain: this
+change does not fix private-HTTP read-aloud validation, default MP3 vs WAV, or
+the unavailable Splicekit service.
diff --git a/integrations/hermes-unraid/webui/my-Hermes-Agent-Web-UI.xml b/integrations/hermes-unraid/webui/my-Hermes-Agent-Web-UI.xml
index 0169736..0b46ffc 100644
--- a/integrations/hermes-unraid/webui/my-Hermes-Agent-Web-UI.xml
+++ b/integrations/hermes-unraid/webui/my-Hermes-Agent-Web-UI.xml
@@ -13,13 +13,13 @@
bash
false
- --env-file=/mnt/nvme-storage/appdata/Hermes-Agent-Web-UI/private/runtime.env --cpus=2 --memory=4g --memory-swap=4g --restart=unless-stopped
+ --env-file=/mnt/nvme-storage/appdata/Hermes-Agent-Web-UI/private/runtime.env --cpus=2 --memory=4g --memory-swap=4g --restart=unless-stopped --stop-timeout=35
Published upstream WebUI image and a private clone of NousResearch/hermes-agent in this container home; existing Webtop workspace.
-
- Eigenständige Hermes WebUI mit eigener Hermes-Kopie und frischen Daten. Nur der Webtop-Workspace wird gemeinsam genutzt. Offizieller Image-Start ohne Gateway oder zusätzliche Startskripte.
+ /bin/bash /opt/hermes-start/start-with-gateway.sh
+ Offizielles Hermes-WebUI-Image mit WebUI und Gateway im selben Container. Eigenes persistentes Startskript für Start, Stop und Fehlerbehandlung; unveränderte Herstellerinitialisierung. Gemeinsamer eigener Hermes-Datenordner und vorhandener Webtop-Workspace.
https://github.com/nesquena/hermes-webui
2026-10-16
- 2026-10-17: Fully recreated with fresh appdata, private upstream checkout and only two home/workspace bind mounts.
+ 2026-10-17: Single-container WebUI + gateway with persistent read-only lifecycle wrapper; restart unless-stopped; no application patches.
@@ -35,4 +35,5 @@
Europe/Berlin
3.14
/config
+ /mnt/nvme-storage/appdata/Hermes-Agent-Web-UI/deployment/start-with-gateway.sh
\ No newline at end of file
diff --git a/integrations/hermes-unraid/webui/single-container-acceptance-2026-10-17.json b/integrations/hermes-unraid/webui/single-container-acceptance-2026-10-17.json
new file mode 100644
index 0000000..bd1a7f0
--- /dev/null
+++ b/integrations/hermes-unraid/webui/single-container-acceptance-2026-10-17.json
@@ -0,0 +1,31 @@
+{
+ "date": "2026-10-17",
+ "container": "Hermes-Agent-Web-UI",
+ "custom_image": false,
+ "application_patches": false,
+ "operator_startup_wrapper": "start-with-gateway.sh",
+ "restart_policy": "unless-stopped",
+ "stop_timeout_seconds": 35,
+ "script_mount_read_only": true,
+ "existing_mcp_definitions": 20,
+ "terminal_backend": "ssh",
+ "scheduled_test": {
+ "mode": "no-agent",
+ "manual_tick": false,
+ "container_restarted_before_due": true,
+ "last_status": "ok",
+ "completed": 1,
+ "marker_matched": true,
+ "test_job_and_script_removed": true
+ },
+ "recovery_test": {
+ "idle_gateway_process_terminated": true,
+ "docker_restart_count_before": 0,
+ "docker_restart_count_after": 1,
+ "webui_healthy_after": true,
+ "gateway_healthy_after": true
+ },
+ "browser_gateway_warning_absent": true,
+ "old_containers_remain_stopped": true,
+ "full_ai_job_and_all_mcp_operations_retested": false
+}
diff --git a/integrations/hermes-unraid/webui/start-with-gateway.sh b/integrations/hermes-unraid/webui/start-with-gateway.sh
new file mode 100644
index 0000000..b9f0b1a
--- /dev/null
+++ b/integrations/hermes-unraid/webui/start-with-gateway.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+# Operator integration: keep the upstream initializer and programs unchanged.
+set -Eeuo pipefail
+web_pid=''
+gateway_pid=''
+stopping=0
+
+stop_children() {
+ (( stopping == 0 )) || return 0
+ stopping=1
+ trap '' TERM INT
+ # Upstream su creates another session. Include descendant process groups,
+ # rather than assuming every child stays in the initial setsid group.
+ # The official image has no ps/awk. Read Linux process metadata with Bash
+ # builtins, handling the parenthesized command field before parsing stat.
+ local -a service_groups=()
+ local -A parents=() groups=() selected=()
+ local stat line state parent group node seen
+ for stat in /proc/[0-9]*/stat; do
+ [[ -r "$stat" ]] || continue
+ line=$(<"$stat") || continue
+ pid=${stat#/proc/}; pid=${pid%/stat}
+ read -r state parent group _ <<< "${line##*) }"
+ parents[$pid]=$parent
+ groups[$pid]=$group
+ done
+ for pid in "${!parents[@]}"; do
+ node=$pid; seen=0
+ while [[ "$node" != "$$" && -n "${parents[$node]:-}" ]] && (( seen++ < 1000 )); do
+ node=${parents[$node]}
+ done
+ group=${groups[$pid]}
+ if [[ "$node" == "$$" ]] && (( group > 1 && group != $$ )); then selected[$group]=1; fi
+ done
+ service_groups=("${!selected[@]}")
+ for pid in "${service_groups[@]}"; do
+ kill -TERM -- "-$pid" 2>/dev/null || true
+ done
+ for (( i=0; i<25; i++ )); do
+ local alive=0
+ for pid in "${service_groups[@]}"; do
+ if kill -0 -- "-$pid" 2>/dev/null; then alive=1; fi
+ done
+ (( alive == 1 )) || break
+ sleep 1
+ done
+ for pid in "${service_groups[@]}"; do
+ kill -KILL -- "-$pid" 2>/dev/null || true
+ done
+ wait 2>/dev/null || true
+}
+trap 'stop_children; exit 0' TERM INT
+trap stop_children EXIT
+
+# setsid gives each service its own process group, including init/su children.
+setsid /hermeswebui_init.bash &
+web_pid=$!
+ready=0
+for (( i=0; i<1200; i++ )); do
+ kill -0 "$web_pid" 2>/dev/null || exit 1
+ if [[ -x /app/venv/bin/hermes ]] && curl -fsS --max-time 2 http://127.0.0.1:8787/health >/dev/null 2>&1; then
+ ready=1
+ break
+ fi
+ sleep 1
+done
+(( ready == 1 )) || exit 1
+
+# The upstream initializer has now prepared the venv and unprivileged user.
+setsid su -s /bin/bash hermeswebui -c 'cd /app/hermes-agent-src; exec /app/venv/bin/hermes gateway run --external-supervisor' &
+gateway_pid=$!
+
+# Any service exit, even a deliberate gateway restart, restarts the whole unit.
+set +e
+wait -n "$web_pid" "$gateway_pid"
+set -e
+exit 1