jackkuo commited on
Commit
a9efc75
·
1 Parent(s): b9f5eb4
Files changed (4) hide show
  1. Dockerfile +5 -2
  2. requirements.txt +1 -3
  3. start_services.sh +62 -0
  4. supervisord.conf +0 -23
Dockerfile CHANGED
@@ -8,5 +8,8 @@ RUN pip install -r requirements.txt
8
  COPY . .
9
 
10
  # Hugging Face Space 必须监听 7860 端口
11
- # 用 supervisor 同时跑 FastAPI(8008) + Gradio(7860)
12
- CMD ["supervisord", "-c", "supervisord.conf"]
 
 
 
 
8
  COPY . .
9
 
10
  # Hugging Face Space 必须监听 7860 端口
11
+ # 用 shell 脚本同时跑 FastAPI(8008) + Gradio(7860)
12
+ # 给启动脚本执行权限
13
+ RUN chmod +x /app/start_services.sh
14
+
15
+ CMD ["/app/start_services.sh"]
requirements.txt CHANGED
@@ -1,6 +1,4 @@
1
  gradio[mcp]>=4.36.0
2
  httpx
3
  fastapi
4
- uvicorn
5
- supervisor
6
- httpx
 
1
  gradio[mcp]>=4.36.0
2
  httpx
3
  fastapi
4
+ uvicorn
 
 
start_services.sh ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # 启动脚本,替代supervisord
3
+
4
+ # 设置错误时退出
5
+ set -e
6
+
7
+ # 函数:启动服务
8
+ start_service() {
9
+ local name=$1
10
+ local command=$2
11
+
12
+ echo "Starting $name..."
13
+ $command &
14
+ local pid=$!
15
+ echo "$name started with PID $pid"
16
+ echo $pid > "/tmp/${name}.pid"
17
+ }
18
+
19
+ # 函数:停止服务
20
+ stop_service() {
21
+ local name=$1
22
+ local pid_file="/tmp/${name}.pid"
23
+
24
+ if [ -f "$pid_file" ]; then
25
+ local pid=$(cat "$pid_file")
26
+ echo "Stopping $name (PID: $pid)..."
27
+ kill -TERM $pid 2>/dev/null || true
28
+ rm -f "$pid_file"
29
+ fi
30
+ }
31
+
32
+ # 函数:清理退出
33
+ cleanup() {
34
+ echo "Received signal, cleaning up..."
35
+ stop_service "fastapi"
36
+ stop_service "gradio"
37
+ exit 0
38
+ }
39
+
40
+ # 设置信号处理
41
+ trap cleanup SIGTERM SIGINT
42
+
43
+ # 启动服务
44
+ start_service "fastapi" "uvicorn server:app --host 0.0.0.0 --port 8008"
45
+ start_service "gradio" "python app.py"
46
+
47
+ # 等待信号
48
+ echo "All services started, waiting for signal..."
49
+ while true; do
50
+ # 检查进程是否还在运行
51
+ if ! kill -0 $(cat /tmp/fastapi.pid 2>/dev/null) 2>/dev/null; then
52
+ echo "FastAPI process died, restarting..."
53
+ start_service "fastapi" "uvicorn server:app --host 0.0.0.0 --port 8008"
54
+ fi
55
+
56
+ if ! kill -0 $(cat /tmp/gradio.pid 2>/dev/null) 2>/dev/null; then
57
+ echo "Gradio process died, restarting..."
58
+ start_service "gradio" "python app.py"
59
+ fi
60
+
61
+ sleep 5
62
+ done
supervisord.conf DELETED
@@ -1,23 +0,0 @@
1
- [supervisord]
2
- nodaemon=true
3
- logfile=/dev/null
4
- logfile_maxbytes=0
5
- pidfile=/tmp/supervisord.pid
6
-
7
- [program:fastapi]
8
- command=uvicorn server:app --host 0.0.0.0 --port 8008
9
- autostart=true
10
- autorestart=true
11
- stdout_logfile=/dev/stdout
12
- stderr_logfile=/dev/stderr
13
- stdout_logfile_maxbytes=0
14
- stderr_logfile_maxbytes=0
15
-
16
- [program:gradio]
17
- command=python app.py
18
- autostart=true
19
- autorestart=true
20
- stdout_logfile=/dev/stdout
21
- stderr_logfile=/dev/stderr
22
- stdout_logfile_maxbytes=0
23
- stderr_logfile_maxbytes=0