From 2e0baa45c04c0cd837f902ad59de53e1da94c27c Mon Sep 17 00:00:00 2001 From: cryptooda Date: Wed, 31 Dec 2025 01:43:41 +0700 Subject: [PATCH] Enhance vibe-dev-server script to include log file monitoring and improved output for API and Workers logs. Implement waiting mechanism for log file creation, and utilize multitail for better log viewing experience. Add cleanup functionality for background processes when exiting. --- scripts/vibe-dev-server.sh | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/scripts/vibe-dev-server.sh b/scripts/vibe-dev-server.sh index fdefef48..92ff4b60 100755 --- a/scripts/vibe-dev-server.sh +++ b/scripts/vibe-dev-server.sh @@ -56,3 +56,88 @@ export VIBE_WORKTREE_ROOT="$WORKTREE_PROJECT_ROOT" # Call main repo's start script bash "$MAIN_REPO/scripts/start-task-docker.sh" "$TASK_ID" "$PORT_OFFSET" + +# Determine log file paths (logs are created in the worktree root) +PID_DIR="$WORKTREE_PROJECT_ROOT/.task-pids" +API_LOG="$PID_DIR/api-${TASK_ID}.log" +WORKERS_LOG="$PID_DIR/workers-${TASK_ID}.log" + +# Wait for log files to be created +echo "" +echo "⏳ Waiting for services to start and log files to be created..." +for i in {1..30}; do + if [ -f "$API_LOG" ] && [ -f "$WORKERS_LOG" ]; then + echo "✅ Log files found" + break + fi + if [ $i -eq 30 ]; then + echo "⚠️ Log files not found after 30 seconds" + echo " API log: $API_LOG" + echo " Workers log: $WORKERS_LOG" + echo " Continuing anyway..." + fi + sleep 1 +done + +# Show logs with labels +echo "" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo "📋 Showing API and Workers logs (Press Ctrl+C to stop)" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo "" + +# Check if log files exist +if [ ! -f "$API_LOG" ] && [ ! -f "$WORKERS_LOG" ]; then + echo "❌ No log files found" + echo " API log: $API_LOG" + echo " Workers log: $WORKERS_LOG" + echo "💡 Services may still be starting. You can manually view logs with:" + echo " tail -f $API_LOG" + echo " tail -f $WORKERS_LOG" + exit 1 +fi + +# Use multitail if available for better viewing, otherwise use simple tail +if command -v multitail >/dev/null 2>&1; then + echo "📋 Using multitail for split-screen log viewing..." + if [ -f "$API_LOG" ] && [ -f "$WORKERS_LOG" ]; then + multitail -s 2 \ + -ci green -T "API" "$API_LOG" \ + -ci yellow -T "Workers" "$WORKERS_LOG" + elif [ -f "$API_LOG" ]; then + tail -f "$API_LOG" + elif [ -f "$WORKERS_LOG" ]; then + tail -f "$WORKERS_LOG" + fi +else + # Simple approach: tail both files with prefixes + # Use a subshell to manage background processes + ( + # Start tailing API logs in background + if [ -f "$API_LOG" ]; then + tail -f "$API_LOG" 2>/dev/null | while IFS= read -r line; do + echo "[API] $line" + done & + TAIL_API_PID=$! + fi + + # Start tailing Workers logs in background + if [ -f "$WORKERS_LOG" ]; then + tail -f "$WORKERS_LOG" 2>/dev/null | while IFS= read -r line; do + echo "[WORKERS] $line" + done & + TAIL_WORKERS_PID=$! + fi + + # Clean up background processes on exit + cleanup() { + [ -n "$TAIL_API_PID" ] && kill "$TAIL_API_PID" 2>/dev/null + [ -n "$TAIL_WORKERS_PID" ] && kill "$TAIL_WORKERS_PID" 2>/dev/null + exit + } + trap cleanup INT TERM EXIT + + # Wait for background processes + wait + ) +fi