From 4afb7638bb4842469e8cd564d883ed72be6cbbf1 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Tue, 30 Sep 2025 10:38:35 +0000 Subject: [PATCH] fix: repair hot-dev script and mock data system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix port conflict: backend now uses 7656, frontend uses 7655 - Fix mock mode not loading: use load_env_file for proper export - Fix pipefail crashes on port checks: disable during lsof checks - Add error handling for /etc/pulse/.env permission issues - Update .gitignore to exclude sensitive files and temp scripts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .gitignore | 17 +++++++++++++++++ scripts/hot-dev.sh | 31 +++++++++++++++++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index dae3db900..e6626129b 100644 --- a/.gitignore +++ b/.gitignore @@ -118,3 +118,20 @@ MOCK_MODE_GUIDE.md # Claude Code Safety Hooks (local only) .claudecode-settings.json .claudecode-hooks/ + +# Sensitive files - DO NOT COMMIT +secrets.env +*secret*.env + +# Development documentation (local only) +CLAUDE_DEV_SETUP.md +AGENT_METRICS_*.md + +# Temporary scripts +tmp_*.py +tmp_*.sh + +# Cloud relay development (separate repo) +cloud-relay/ +scripts/agent/ +docs/internal/ diff --git a/scripts/hot-dev.sh b/scripts/hot-dev.sh index 57fe8e6a2..ef0b57e36 100755 --- a/scripts/hot-dev.sh +++ b/scripts/hot-dev.sh @@ -27,7 +27,7 @@ PORT=${PORT:-${FRONTEND_PORT}} FRONTEND_DEV_HOST=${FRONTEND_DEV_HOST:-0.0.0.0} FRONTEND_DEV_PORT=${FRONTEND_DEV_PORT:-${FRONTEND_PORT}} PULSE_DEV_API_HOST=${PULSE_DEV_API_HOST:-127.0.0.1} -PULSE_DEV_API_PORT=${PULSE_DEV_API_PORT:-${FRONTEND_PORT}} +PULSE_DEV_API_PORT=${PULSE_DEV_API_PORT:-7656} if [[ -z ${PULSE_DEV_API_URL:-} ]]; then PULSE_DEV_API_URL="http://${PULSE_DEV_API_HOST}:${PULSE_DEV_API_PORT}" @@ -65,7 +65,7 @@ BANNER kill_port() { local port=$1 printf "[hot-dev] Cleaning up port %s...\n" "${port}" - lsof -i :"${port}" | awk 'NR>1 {print $2}' | xargs -r kill -9 2>/dev/null + lsof -i :"${port}" 2>/dev/null | awk 'NR>1 {print $2}' | xargs -r kill -9 2>/dev/null || true } printf "[hot-dev] Cleaning up existing processes...\n" @@ -89,45 +89,48 @@ kill_port "${EXTRA_CLEANUP_PORT}" sleep 3 -if lsof -i :"${FRONTEND_DEV_PORT}" | grep -q LISTEN; then +# Temporarily disable pipefail for port checks (lsof returns 1 when port is free) +set +o pipefail + +if lsof -i :"${FRONTEND_DEV_PORT}" 2>/dev/null | grep -q LISTEN; then echo "ERROR: Port ${FRONTEND_DEV_PORT} is still in use after cleanup!" kill_port "${FRONTEND_DEV_PORT}" sleep 2 - if lsof -i :"${FRONTEND_DEV_PORT}" | grep -q LISTEN; then + if lsof -i :"${FRONTEND_DEV_PORT}" 2>/dev/null | grep -q LISTEN; then echo "FATAL: Cannot free port ${FRONTEND_DEV_PORT}. Please manually kill the process:" lsof -i :"${FRONTEND_DEV_PORT}" exit 1 fi fi -if lsof -i :"${PULSE_DEV_API_PORT}" | grep -q LISTEN; then +if lsof -i :"${PULSE_DEV_API_PORT}" 2>/dev/null | grep -q LISTEN; then echo "ERROR: Port ${PULSE_DEV_API_PORT} is still in use after cleanup!" kill_port "${PULSE_DEV_API_PORT}" sleep 2 - if lsof -i :"${PULSE_DEV_API_PORT}" | grep -q LISTEN; then + if lsof -i :"${PULSE_DEV_API_PORT}" 2>/dev/null | grep -q LISTEN; then echo "FATAL: Cannot free port ${PULSE_DEV_API_PORT}. Please manually kill the process:" lsof -i :"${PULSE_DEV_API_PORT}" exit 1 fi fi +# Re-enable pipefail +set -o pipefail + echo "Ports are clean!" if [[ -f "${ROOT_DIR}/mock.env" ]]; then - set +u - # shellcheck disable=SC1090 - source "${ROOT_DIR}/mock.env" - set -u + load_env_file "${ROOT_DIR}/mock.env" if [[ ${PULSE_MOCK_MODE:-false} == "true" ]]; then TOTAL_GUESTS=$((PULSE_MOCK_NODES * (PULSE_MOCK_VMS_PER_NODE + PULSE_MOCK_LXCS_PER_NODE))) echo "Mock mode ENABLED with ${PULSE_MOCK_NODES} nodes (${TOTAL_GUESTS} total guests)" fi fi -if [[ -f /etc/pulse/.env ]]; then +if [[ -f /etc/pulse/.env ]] && [[ -r /etc/pulse/.env ]]; then set +u # shellcheck disable=SC1091 - source /etc/pulse/.env + source /etc/pulse/.env 2>/dev/null || true set -u echo "Auth configuration loaded from /etc/pulse/.env" fi @@ -137,8 +140,8 @@ cd "${ROOT_DIR}" go build -o pulse ./cmd/pulse -export PULSE_MOCK_MODE PULSE_MOCK_NODES PULSE_MOCK_VMS_PER_NODE PULSE_MOCK_LXCS_PER_NODE PULSE_MOCK_RANDOM_METRICS PULSE_MOCK_STOPPED_PERCENT -export PULSE_AUTH_USER PULSE_AUTH_PASS +# Mock variables already exported via load_env_file (set -a) +# Just export the port variables for the backend FRONTEND_PORT=${PULSE_DEV_API_PORT} PORT=${PULSE_DEV_API_PORT} export FRONTEND_PORT PULSE_DEV_API_PORT PORT