From 53f7ef84d24598ba409a6ea0d74ab7d1e6c23112 Mon Sep 17 00:00:00 2001 From: Felipe Domingues <53182096+domfelipe@users.noreply.github.com> Date: Wed, 29 Apr 2026 07:23:29 -0300 Subject: [PATCH] Update entrypoint.sh --- entrypoint.sh | 71 ++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2e95186..1249f84 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,51 +1,58 @@ #!/usr/bin/env bash -set -e +set -Eeuo pipefail -HERMES_DATA_DIR="${HERMES_DATA_DIR:-/opt/data}" -HERMES_CONFIG_DIR="${HERMES_DATA_DIR}/.hermes" -SOUL_FILE="${HERMES_CONFIG_DIR}/SOUL.md" +INTERNAL_HOST="${INTERNAL_HOST:-127.0.0.1}" +INTERNAL_PORT="${INTERNAL_PORT:-8000}" +PUBLIC_HOST="${PUBLIC_HOST:-0.0.0.0}" +PUBLIC_PORT="${PORT:-${PUBLIC_PORT:-8642}}" -mkdir -p "${HERMES_CONFIG_DIR}" +HERMES_HOME="${HERMES_HOME:-/opt/data/.hermes}" +SOUL_PATH="${SOUL_PATH:-$HERMES_HOME/SOUL.md}" + +mkdir -p "$HERMES_HOME" -# Aplica override do SOUL.md se a env estiver setada if [ -n "${HERMES_SOUL_OVERRIDE:-}" ]; then - echo "[entrypoint] Applying HERMES_SOUL_OVERRIDE to ${SOUL_FILE}" - printf '%s' "${HERMES_SOUL_OVERRIDE}" > "${SOUL_FILE}" + echo "[entrypoint] Applying HERMES_SOUL_OVERRIDE to $SOUL_PATH" + printf '%s\n' "$HERMES_SOUL_OVERRIDE" > "$SOUL_PATH" fi -# Garante permissões corretas (caso o volume tenha sido montado externamente) -chown -R hermes:hermes "${HERMES_DATA_DIR}" || true - -INTERNAL_HOST="127.0.0.1" -INTERNAL_PORT="8000" -PUBLIC_HOST="0.0.0.0" -PUBLIC_PORT="${PORT:-8642}" - -echo "[entrypoint] Hermes interno: ${INTERNAL_HOST}:${INTERNAL_PORT}" -echo "[entrypoint] Proxy público: ${PUBLIC_HOST}:${PUBLIC_PORT}" +echo "[entrypoint] Hermes interno: $INTERNAL_HOST:$INTERNAL_PORT" +echo "[entrypoint] Proxy público: $PUBLIC_HOST:$PUBLIC_PORT" echo "[entrypoint] Iniciando Hermes original..." -# Inicia o Hermes original em background como usuário hermes -su -s /bin/bash hermes -c "cd /opt/hermes && hermes dashboard --host "$HERMES_INTERNAL_HOST" --port "$HERMES_INTERNAL_PORT" --no-open && -HERMES_PID=$! +hermes dashboard \ + --host "$INTERNAL_HOST" \ + --port "$INTERNAL_PORT" \ + --no-open & + +HERMES_PID="$!" + +echo "[entrypoint] Aguardando Hermes responder em $INTERNAL_HOST:$INTERNAL_PORT..." -# Aguarda Hermes ficar pronto -echo "[entrypoint] Aguardando Hermes responder em ${INTERNAL_HOST}:${INTERNAL_PORT}..." for i in $(seq 1 60); do - if ! kill -0 "${HERMES_PID}" 2>/dev/null; then + if ! kill -0 "$HERMES_PID" 2>/dev/null; then echo "[entrypoint] ERRO: Hermes morreu antes de ficar pronto" + wait "$HERMES_PID" exit 1 fi - if curl -sf "http://${INTERNAL_HOST}:${INTERNAL_PORT}/health" > /dev/null 2>&1; then - echo "[entrypoint] Hermes pronto!" + + if curl -fsS "http://$INTERNAL_HOST:$INTERNAL_PORT" >/dev/null 2>&1; then + echo "[entrypoint] Hermes pronto" break fi + sleep 1 done -# Inicia o proxy / skills_api público -echo "[entrypoint] Iniciando skills_api em ${PUBLIC_HOST}:${PUBLIC_PORT}..." -exec python -m skills_api \ - --host "${PUBLIC_HOST}" \ - --port "${PUBLIC_PORT}" \ - --upstream "http://${INTERNAL_HOST}:${INTERNAL_PORT}" +if ! kill -0 "$HERMES_PID" 2>/dev/null; then + echo "[entrypoint] ERRO: Hermes morreu antes de ficar pronto" + wait "$HERMES_PID" + exit 1 +fi + +echo "[entrypoint] Iniciando proxy público em $PUBLIC_HOST:$PUBLIC_PORT..." + +exec python /opt/hermes-custom/skills_api.py \ + --host "$PUBLIC_HOST" \ + --port "$PUBLIC_PORT" \ + --target "http://$INTERNAL_HOST:$INTERNAL_PORT"