Spaces:
Build error
Build error
Update entrypoint.sh
Browse files- entrypoint.sh +103 -27
entrypoint.sh
CHANGED
|
@@ -1,15 +1,52 @@
|
|
| 1 |
#!/bin/bash
|
|
|
|
| 2 |
|
| 3 |
# Enable error tracing
|
| 4 |
-
set -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Make sure `/data/db` directory exists even with persistent storage
|
| 10 |
mkdir -p /data/db
|
| 11 |
# If app crashed, mongo didn't stop gracefully. Remove all the old *.lock files
|
| 12 |
find /data/db -name "*.lock" -type f -exec rm -f {} \;
|
|
|
|
| 13 |
# Start the local Mongo database
|
| 14 |
echo "Starting MongoDB..."
|
| 15 |
mongod &
|
|
@@ -19,54 +56,93 @@ echo "MongoDB started with PID: $MONGO_PID"
|
|
| 19 |
# Check if MongoDB is running
|
| 20 |
sleep 5
|
| 21 |
if ! kill -0 $MONGO_PID 2>/dev/null; then
|
| 22 |
-
echo "ERROR: MongoDB failed to start!"
|
|
|
|
| 23 |
exit 1
|
| 24 |
fi
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
echo "
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
echo "
|
| 33 |
-
echo "
|
| 34 |
-
find / -name "libpython3.11.so*" 2>/dev/null || echo "Library not found"
|
| 35 |
|
| 36 |
-
# Start text-generation-inference with
|
| 37 |
-
text-generation-
|
|
|
|
| 38 |
TGI_PID=$!
|
| 39 |
echo "Text-generation-inference started with PID: $TGI_PID"
|
| 40 |
|
| 41 |
# Check if TGI is running after a brief moment
|
| 42 |
sleep 10
|
| 43 |
if ! kill -0 $TGI_PID 2>/dev/null; then
|
| 44 |
-
echo "ERROR: text-generation-inference process died!
|
|
|
|
| 45 |
exit 1
|
| 46 |
fi
|
| 47 |
|
| 48 |
-
# Wait for text-generation-inference to start
|
| 49 |
echo "Waiting for text-generation-inference to become available..."
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Start the chat-ui process
|
| 53 |
echo "Starting chat-ui..."
|
| 54 |
-
dotenv -e /app/.env -c -- node /app/build/index.js -- --host 0.0.0.0 --port 3000 &
|
| 55 |
CHAT_UI_PID=$!
|
| 56 |
|
| 57 |
# Check if chat-ui is running
|
| 58 |
sleep 5
|
| 59 |
if ! kill -0 $CHAT_UI_PID 2>/dev/null; then
|
| 60 |
-
echo "ERROR: chat-ui process died!
|
|
|
|
| 61 |
exit 1
|
| 62 |
fi
|
| 63 |
|
| 64 |
-
echo "All services are running!"
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
|
| 4 |
# Enable error tracing
|
| 5 |
+
set -x
|
| 6 |
+
|
| 7 |
+
# Print system information
|
| 8 |
+
echo "=== System Information ==="
|
| 9 |
+
uname -a
|
| 10 |
+
cat /etc/os-release
|
| 11 |
+
echo "=== CPU Information ==="
|
| 12 |
+
cat /proc/cpuinfo | grep "model name" | head -1
|
| 13 |
+
echo "=== Memory Information ==="
|
| 14 |
+
free -h
|
| 15 |
+
echo "=== Disk Information ==="
|
| 16 |
+
df -h
|
| 17 |
+
|
| 18 |
+
# Print environment variables
|
| 19 |
+
echo "=== Environment Variables ==="
|
| 20 |
+
env | sort
|
| 21 |
+
|
| 22 |
+
# Check Python installation
|
| 23 |
+
echo "=== Python Information ==="
|
| 24 |
+
which python3.11 || echo "Python 3.11 not found in PATH"
|
| 25 |
+
python3.11 --version || echo "Failed to get Python version"
|
| 26 |
+
echo "PYTHONPATH: $PYTHONPATH"
|
| 27 |
+
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
|
| 28 |
+
|
| 29 |
+
# Check Python libraries
|
| 30 |
+
echo "=== Python Libraries ==="
|
| 31 |
+
find /usr -name "libpython3.11.so*" 2>/dev/null || echo "Library not found in /usr"
|
| 32 |
+
find /lib -name "libpython3.11.so*" 2>/dev/null || echo "Library not found in /lib"
|
| 33 |
+
find /usr/local -name "libpython3.11.so*" 2>/dev/null || echo "Library not found in /usr/local"
|
| 34 |
|
| 35 |
+
# Dynamically find and add Python library paths
|
| 36 |
+
for path in $(find / -name "libpython3.11.so*" 2>/dev/null | xargs dirname 2>/dev/null | sort | uniq); do
|
| 37 |
+
if [ -n "$path" ]; then
|
| 38 |
+
echo "Adding Python library path: $path"
|
| 39 |
+
export LD_LIBRARY_PATH="$path:$LD_LIBRARY_PATH"
|
| 40 |
+
fi
|
| 41 |
+
done
|
| 42 |
+
|
| 43 |
+
echo "Updated LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
|
| 44 |
|
| 45 |
# Make sure `/data/db` directory exists even with persistent storage
|
| 46 |
mkdir -p /data/db
|
| 47 |
# If app crashed, mongo didn't stop gracefully. Remove all the old *.lock files
|
| 48 |
find /data/db -name "*.lock" -type f -exec rm -f {} \;
|
| 49 |
+
|
| 50 |
# Start the local Mongo database
|
| 51 |
echo "Starting MongoDB..."
|
| 52 |
mongod &
|
|
|
|
| 56 |
# Check if MongoDB is running
|
| 57 |
sleep 5
|
| 58 |
if ! kill -0 $MONGO_PID 2>/dev/null; then
|
| 59 |
+
echo "ERROR: MongoDB failed to start! Here's the MongoDB log:"
|
| 60 |
+
cat /data/db/mongod.log || echo "No MongoDB log found"
|
| 61 |
exit 1
|
| 62 |
fi
|
| 63 |
|
| 64 |
+
# Create a test file to check filesystem permissions
|
| 65 |
+
echo "Testing file system permissions..."
|
| 66 |
+
touch /app/test_write_permissions.txt && rm /app/test_write_permissions.txt
|
| 67 |
+
echo "Filesystem permissions OK"
|
| 68 |
+
|
| 69 |
+
# Check if text-generation-launcher exists
|
| 70 |
+
echo "Checking for text-generation-launcher..."
|
| 71 |
+
which text-generation-launcher || { echo "text-generation-launcher not found!"; exit 1; }
|
|
|
|
| 72 |
|
| 73 |
+
# Start the text-generation-inference process with error redirection
|
| 74 |
+
echo "Starting text-generation-inference with model: ${MODEL_NAME}"
|
| 75 |
+
text-generation-launcher --model-id ${MODEL_NAME} --num-shard 1 --port 8080 --trust-remote-code > /app/tgi.log 2>&1 &
|
| 76 |
TGI_PID=$!
|
| 77 |
echo "Text-generation-inference started with PID: $TGI_PID"
|
| 78 |
|
| 79 |
# Check if TGI is running after a brief moment
|
| 80 |
sleep 10
|
| 81 |
if ! kill -0 $TGI_PID 2>/dev/null; then
|
| 82 |
+
echo "ERROR: text-generation-inference process died! Here's the log:"
|
| 83 |
+
cat /app/tgi.log || echo "No TGI log found"
|
| 84 |
exit 1
|
| 85 |
fi
|
| 86 |
|
| 87 |
+
# Wait for text-generation-inference to start with better error handling
|
| 88 |
echo "Waiting for text-generation-inference to become available..."
|
| 89 |
+
MAX_RETRIES=30
|
| 90 |
+
RETRY_COUNT=0
|
| 91 |
+
while ! curl -s http://127.0.0.1:8080/health > /dev/null; do
|
| 92 |
+
RETRY_COUNT=$((RETRY_COUNT+1))
|
| 93 |
+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
|
| 94 |
+
echo "ERROR: Maximum retries reached waiting for text-generation-inference!"
|
| 95 |
+
echo "TGI log content:"
|
| 96 |
+
cat /app/tgi.log || echo "No TGI log found"
|
| 97 |
+
exit 1
|
| 98 |
+
fi
|
| 99 |
+
echo "Waiting for text-generation-inference... Retry $RETRY_COUNT of $MAX_RETRIES"
|
| 100 |
+
sleep 10
|
| 101 |
+
done
|
| 102 |
|
| 103 |
# Start the chat-ui process
|
| 104 |
echo "Starting chat-ui..."
|
| 105 |
+
dotenv -e /app/.env -c -- node /app/build/index.js -- --host 0.0.0.0 --port 3000 > /app/chat-ui.log 2>&1 &
|
| 106 |
CHAT_UI_PID=$!
|
| 107 |
|
| 108 |
# Check if chat-ui is running
|
| 109 |
sleep 5
|
| 110 |
if ! kill -0 $CHAT_UI_PID 2>/dev/null; then
|
| 111 |
+
echo "ERROR: chat-ui process died! Here's the log:"
|
| 112 |
+
cat /app/chat-ui.log || echo "No chat-ui log found"
|
| 113 |
exit 1
|
| 114 |
fi
|
| 115 |
|
| 116 |
+
echo "All services are running! Monitoring processes..."
|
| 117 |
|
| 118 |
+
# Function to check if a service is still running
|
| 119 |
+
check_service() {
|
| 120 |
+
SERVICE_NAME=$1
|
| 121 |
+
PID=$2
|
| 122 |
+
if ! kill -0 $PID 2>/dev/null; then
|
| 123 |
+
echo "ERROR: $SERVICE_NAME with PID $PID has stopped!"
|
| 124 |
+
return 1
|
| 125 |
+
fi
|
| 126 |
+
return 0
|
| 127 |
+
}
|
| 128 |
|
| 129 |
+
# Monitor all services
|
| 130 |
+
while true; do
|
| 131 |
+
if ! check_service "MongoDB" $MONGO_PID; then
|
| 132 |
+
cat /data/db/mongod.log || echo "No MongoDB log found"
|
| 133 |
+
exit 1
|
| 134 |
+
fi
|
| 135 |
+
|
| 136 |
+
if ! check_service "Text-generation-inference" $TGI_PID; then
|
| 137 |
+
cat /app/tgi.log || echo "No TGI log found"
|
| 138 |
+
exit 1
|
| 139 |
+
fi
|
| 140 |
+
|
| 141 |
+
if ! check_service "Chat-UI" $CHAT_UI_PID; then
|
| 142 |
+
cat /app/chat-ui.log || echo "No chat-ui log found"
|
| 143 |
+
exit 1
|
| 144 |
+
fi
|
| 145 |
+
|
| 146 |
+
echo "All services running: MongoDB ($MONGO_PID), TGI ($TGI_PID), Chat-UI ($CHAT_UI_PID)"
|
| 147 |
+
sleep 60
|
| 148 |
+
done
|