mirror of
https://github.com/domfelipe/hermes-agent-custom.git
synced 2026-08-07 06:56:41 +00:00
Update entrypoint.sh
This commit is contained in:
parent
919377e5fc
commit
e49fdb6124
1 changed files with 34 additions and 45 deletions
|
|
@ -1,62 +1,51 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# ===========================================================
|
HERMES_DATA_DIR="${HERMES_DATA_DIR:-/opt/data}"
|
||||||
# Hermes Fork Entrypoint — Reverse Proxy Strategy
|
HERMES_CONFIG_DIR="${HERMES_DATA_DIR}/.hermes"
|
||||||
# ===========================================================
|
SOUL_FILE="${HERMES_CONFIG_DIR}/SOUL.md"
|
||||||
# 1) Hermes original roda em 127.0.0.1:8000 (interno)
|
|
||||||
# 2) skills_api.py roda em 0.0.0.0:$PORT (público)
|
|
||||||
# - intercepta /api/skills/*
|
|
||||||
# - proxy todo o resto para o Hermes
|
|
||||||
# ===========================================================
|
|
||||||
|
|
||||||
# Suspensão (mantém compatibilidade com a flag HERMES_SUSPENDED)
|
mkdir -p "${HERMES_CONFIG_DIR}"
|
||||||
if [ "$HERMES_SUSPENDED" = "true" ]; then
|
|
||||||
echo "[entrypoint] Agent suspended — sleeping forever"
|
# Aplica override do SOUL.md se a env estiver setada
|
||||||
exec sleep infinity
|
if [ -n "${HERMES_SOUL_OVERRIDE:-}" ]; then
|
||||||
|
echo "[entrypoint] Applying HERMES_SOUL_OVERRIDE to ${SOUL_FILE}"
|
||||||
|
printf '%s' "${HERMES_SOUL_OVERRIDE}" > "${SOUL_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Aplica SOUL override se presente
|
# Garante permissões corretas (caso o volume tenha sido montado externamente)
|
||||||
if [ -n "$HERMES_SOUL_OVERRIDE" ]; then
|
chown -R hermes:hermes "${HERMES_DATA_DIR}" || true
|
||||||
echo "[entrypoint] Applying HERMES_SOUL_OVERRIDE to /opt/data/SOUL.md"
|
|
||||||
mkdir -p /opt/data
|
|
||||||
echo "$HERMES_SOUL_OVERRIDE" > /opt/data/SOUL.md
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Porta interna do Hermes (não exposta publicamente)
|
INTERNAL_HOST="127.0.0.1"
|
||||||
export HERMES_INTERNAL_PORT="${HERMES_INTERNAL_PORT:-8000}"
|
INTERNAL_PORT="8000"
|
||||||
|
PUBLIC_HOST="0.0.0.0"
|
||||||
|
PUBLIC_PORT="${PORT:-8642}"
|
||||||
|
|
||||||
# Porta pública (Railway define $PORT automaticamente)
|
echo "[entrypoint] Hermes interno: ${INTERNAL_HOST}:${INTERNAL_PORT}"
|
||||||
export PUBLIC_PORT="${PORT:-8642}"
|
echo "[entrypoint] Proxy público: ${PUBLIC_HOST}:${PUBLIC_PORT}"
|
||||||
|
|
||||||
echo "[entrypoint] Hermes interno: 127.0.0.1:${HERMES_INTERNAL_PORT}"
|
|
||||||
echo "[entrypoint] Proxy público: 0.0.0.0:${PUBLIC_PORT}"
|
|
||||||
|
|
||||||
# Força o Hermes a escutar só no localhost numa porta interna
|
|
||||||
# Sobrescreve qualquer PORT que o Hermes leia
|
|
||||||
export API_SERVER_PORT="${HERMES_INTERNAL_PORT}"
|
|
||||||
export API_SERVER_HOST="127.0.0.1"
|
|
||||||
|
|
||||||
# Inicia Hermes em background
|
|
||||||
echo "[entrypoint] Iniciando Hermes original..."
|
echo "[entrypoint] Iniciando Hermes original..."
|
||||||
PORT="${HERMES_INTERNAL_PORT}" /opt/hermes/docker/entrypoint.sh gateway run &
|
|
||||||
|
# Inicia o Hermes original em background como usuário hermes
|
||||||
|
su -s /bin/bash hermes -c "cd /opt/hermes && python -m hermes_agent serve --host ${INTERNAL_HOST} --port ${INTERNAL_PORT}" &
|
||||||
HERMES_PID=$!
|
HERMES_PID=$!
|
||||||
|
|
||||||
# Aguarda Hermes ficar pronto (até 60s)
|
# Aguarda Hermes ficar pronto
|
||||||
echo "[entrypoint] Aguardando Hermes responder em 127.0.0.1:${HERMES_INTERNAL_PORT}..."
|
echo "[entrypoint] Aguardando Hermes responder em ${INTERNAL_HOST}:${INTERNAL_PORT}..."
|
||||||
for i in $(seq 1 60); do
|
for i in $(seq 1 60); do
|
||||||
if curl -sf "http://127.0.0.1:${HERMES_INTERNAL_PORT}/" > /dev/null 2>&1 \
|
if ! kill -0 "${HERMES_PID}" 2>/dev/null; then
|
||||||
|| curl -sf "http://127.0.0.1:${HERMES_INTERNAL_PORT}/health" > /dev/null 2>&1; then
|
|
||||||
echo "[entrypoint] Hermes está pronto!"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
if ! kill -0 $HERMES_PID 2>/dev/null; then
|
|
||||||
echo "[entrypoint] ERRO: Hermes morreu antes de ficar pronto"
|
echo "[entrypoint] ERRO: Hermes morreu antes de ficar pronto"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if curl -sf "http://${INTERNAL_HOST}:${INTERNAL_PORT}/health" > /dev/null 2>&1; then
|
||||||
|
echo "[entrypoint] Hermes pronto!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
# Inicia o proxy + skills_api no foreground (na porta pública)
|
# Inicia o proxy / skills_api público
|
||||||
echo "[entrypoint] Iniciando proxy + skills_api em 0.0.0.0:${PUBLIC_PORT}..."
|
echo "[entrypoint] Iniciando skills_api em ${PUBLIC_HOST}:${PUBLIC_PORT}..."
|
||||||
exec python3 /opt/hermes-custom/skills_api.py
|
exec python -m skills_api \
|
||||||
|
--host "${PUBLIC_HOST}" \
|
||||||
|
--port "${PUBLIC_PORT}" \
|
||||||
|
--upstream "http://${INTERNAL_HOST}:${INTERNAL_PORT}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue