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