james20141606 commited on
Commit
c460cf9
·
verified ·
1 Parent(s): 301855d

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +35 -16
entrypoint.sh CHANGED
@@ -1,22 +1,41 @@
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
 
10
- # Start the text-generation-inference process
11
- text-generation-launcher --model-id ${MODEL_NAME} --num-shard 1 --port 8080 --trust-remote-code &
12
 
13
- # Wait for text-generation-inference to start
14
- curl --retry 60 --retry-delay 10 --retry-connrefused http://127.0.0.1:8080/health
 
 
 
 
 
 
 
15
 
16
- # Start the chat-ui process
17
- dotenv -e /app/.env -c -- node /app/build/index.js -- --host 0.0.0.0 --port 3000
18
- # Wait for any process to exit
19
- wait -n
20
 
21
- # Exit with status of process that exited first
22
- exit $?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
 
4
+ # 1) 本地 Mongo 启动(容器内)
5
  mkdir -p /data/db
6
+ # 清理可能遗留的锁文件,避免上次异常退出导致无法启动
7
+ find /data/db -name "*.lock" -type f -exec rm -f {} \;
 
 
8
 
9
+ # 建议绑定到回环即可;写日志到临时目录;后台运行
10
+ mongod --dbpath /data/db --bind_ip 127.0.0.1 --logpath /tmp/mongod.log --fork
11
 
12
+ # 等待 Mongo 就绪(简单轮询 60 次,每次 1s)
13
+ for i in $(seq 1 60); do
14
+ if mongosh --quiet --host 127.0.0.1 --eval 'db.runCommand({ping:1})' >/dev/null 2>&1; then
15
+ echo "MongoDB is up."
16
+ break
17
+ fi
18
+ echo "Waiting for MongoDB to be ready... ($i/60)"
19
+ sleep 1
20
+ done
21
 
22
+ # 如果外部没有注入 Atlas MONGODB_URL,就默认用本地
23
+ export MONGODB_URL="${MONGODB_URL:-mongodb://127.0.0.1:27017/chatui}"
 
 
24
 
25
+ # 2) 校验外部 LLM 所需环境
26
+ : "${OPENAI_BASE_URL:?OPENAI_BASE_URL missing}"
27
+ : "${OPENAI_API_KEY:?OPENAI_API_KEY missing}"
28
+ : "${MODEL_NAME:?MODEL_NAME missing}"
29
+
30
+ echo "Using MODEL_NAME=$MODEL_NAME"
31
+ echo "Using OPENAI_BASE_URL=$OPENAI_BASE_URL"
32
+ echo "MongoDB URL set to: ${MONGODB_URL}"
33
+
34
+ # 3) 启动 ChatUI
35
+ # - 若容器里有 dotenv-cli,则用它加载 /app/.env(若存在)
36
+ # - 否则直接起 node
37
+ if command -v dotenv >/dev/null 2>&1 && [ -f /app/.env ]; then
38
+ exec dotenv -e /app/.env -c -- node /app/build/index.js -- --host 0.0.0.0 --port 3000
39
+ else
40
+ exec node /app/build/index.js --host 0.0.0.0 --port 3000
41
+ fi