dev.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. cd ../../../
  3. # Check and install git hooks if missing
  4. check_and_install_hooks() {
  5. local hooks_missing=false
  6. # Check for required hooks
  7. if [ ! -f ".git/hooks/pre-commit" ] || [ ! -f ".git/hooks/pre-push" ] || [ ! -f ".git/hooks/post-push" ]; then
  8. hooks_missing=true
  9. fi
  10. if [ "$hooks_missing" = true ]; then
  11. echo "🔧 Git hooks missing, installing them..."
  12. cd tools/server/webui
  13. if bash scripts/install-git-hooks.sh; then
  14. echo "✅ Git hooks installed successfully"
  15. else
  16. echo "⚠️ Failed to install git hooks, continuing anyway..."
  17. fi
  18. cd ../../../
  19. else
  20. echo "✅ Git hooks already installed"
  21. fi
  22. }
  23. # Install git hooks if needed
  24. check_and_install_hooks
  25. # Check if llama-server binary already exists
  26. if [ ! -f "build/bin/llama-server" ]; then
  27. echo "Building llama-server..."
  28. cmake -B build && cmake --build build --config Release -t llama-server
  29. else
  30. echo "llama-server binary already exists, skipping build."
  31. fi
  32. # Start llama-server and capture output
  33. echo "Starting llama-server..."
  34. mkfifo server_output.pipe
  35. build/bin/llama-server -hf ggml-org/gpt-oss-20b-GGUF --jinja -c 0 --no-webui > server_output.pipe 2>&1 &
  36. SERVER_PID=$!
  37. # Function to wait for server to be ready
  38. wait_for_server() {
  39. echo "Waiting for llama-server to be ready..."
  40. local max_wait=60
  41. local start_time=$(date +%s)
  42. # Read server output in background and look for the ready message
  43. (
  44. while IFS= read -r line; do
  45. echo "🔍 Server: $line"
  46. if [[ "$line" == *"server is listening on http://127.0.0.1:8080 - starting the main loop"* ]]; then
  47. echo "✅ llama-server is ready!"
  48. echo "READY" > server_ready.flag
  49. break
  50. fi
  51. done < server_output.pipe
  52. ) &
  53. # Wait for ready flag or timeout
  54. while [ ! -f server_ready.flag ]; do
  55. local current_time=$(date +%s)
  56. local elapsed=$((current_time - start_time))
  57. if [ $elapsed -ge $max_wait ]; then
  58. echo "❌ Server failed to start within $max_wait seconds"
  59. rm -f server_ready.flag
  60. return 1
  61. fi
  62. sleep 1
  63. done
  64. rm -f server_ready.flag
  65. return 0
  66. }
  67. # Cleanup function
  68. cleanup() {
  69. echo "🧹 Cleaning up..."
  70. kill $SERVER_PID 2>/dev/null
  71. rm -f server_output.pipe server_ready.flag
  72. exit
  73. }
  74. # Set up signal handlers
  75. trap cleanup SIGINT SIGTERM
  76. # Wait for server to be ready
  77. if wait_for_server; then
  78. echo "🚀 Starting development servers..."
  79. cd tools/server/webui
  80. storybook dev -p 6006 --ci & vite dev --host 0.0.0.0 &
  81. # Wait for all background processes
  82. wait
  83. else
  84. echo "❌ Failed to start development environment"
  85. cleanup
  86. fi