WebHub360 commited on
Commit
8f83968
·
verified ·
1 Parent(s): ec130d9

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +21 -117
entrypoint.sh CHANGED
@@ -1,148 +1,52 @@
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 &
53
  MONGO_PID=$!
54
  echo "MongoDB started with PID: $MONGO_PID"
55
 
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
 
1
  #!/bin/bash
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # Make sure `/data/db` directory exists even with persistent storage
4
  mkdir -p /data/db
5
  # If app crashed, mongo didn't stop gracefully. Remove all the old *.lock files
6
  find /data/db -name "*.lock" -type f -exec rm -f {} \;
 
7
  # Start the local Mongo database
 
8
  mongod &
9
  MONGO_PID=$!
10
  echo "MongoDB started with PID: $MONGO_PID"
11
 
12
+ # Display model being loaded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  echo "Starting text-generation-inference with model: ${MODEL_NAME}"
14
+
15
+ # Start the text-generation-inference process with error logging
16
+ text-generation-launcher --model-id ${MODEL_NAME} --num-shard 1 --port 8080 --trust-remote-code > /tmp/tgi.log 2>&1 &
17
  TGI_PID=$!
18
  echo "Text-generation-inference started with PID: $TGI_PID"
19
 
20
+ # Check if process is running
21
+ sleep 5
22
  if ! kill -0 $TGI_PID 2>/dev/null; then
23
+ echo "ERROR: text-generation-inference process died! Log:"
24
+ cat /tmp/tgi.log
25
  exit 1
26
  fi
27
 
28
+ # Wait for text-generation-inference to start
29
+ echo "Waiting for text-generation-inference to be available..."
30
+ curl --retry 60 --retry-delay 10 --retry-connrefused http://127.0.0.1:8080/health
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # Start the chat-ui process
33
  echo "Starting chat-ui..."
34
+ dotenv -e /app/.env -c -- node /app/build/index.js -- --host 0.0.0.0 --port 3000 &
35
  CHAT_UI_PID=$!
36
 
37
+ # Check if process is running
38
  sleep 5
39
  if ! kill -0 $CHAT_UI_PID 2>/dev/null; then
40
+ echo "ERROR: chat-ui process died!"
 
41
  exit 1
42
  fi
43
 
44
+ echo "All services are now running"
45
 
46
+ # Wait for any process to exit
47
+ wait -n
 
 
 
 
 
 
 
 
48
 
49
+ # Exit with status of process that exited first
50
+ EXIT_CODE=$?
51
+ echo "A process exited with code: $EXIT_CODE"
52
+ exit $EXIT_CODE