baxin commited on
Commit
3580b8b
·
verified ·
1 Parent(s): bb3ec82

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +31 -10
entrypoint.sh CHANGED
@@ -1,25 +1,46 @@
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
- # (任意) venv を使っているなら有効化
5
  if [ -f "/home/user/app/.venv/bin/activate" ]; then
6
  source /home/user/app/.venv/bin/activate
7
  fi
8
 
9
- # HF Spaces / Gradio の公開設定(超重要)
10
  export GRADIO_SERVER_NAME="${GRADIO_SERVER_NAME:-0.0.0.0}"
11
  export GRADIO_SERVER_PORT="${GRADIO_SERVER_PORT:-7860}"
12
  export PORT="${PORT:-7860}"
13
 
14
- # robot-server を使うなら起動(devが永遠に走るならバックグラウンド化)
15
- if [ -d "/root/opentrons/robot-server" ]; then
16
- echo "[entrypoint] starting robot-server..."
17
- # dev が foreground で張り付く想定なのでバックグラウンドに回す
18
- (cd /root/opentrons && make -C robot-server dev-flex) &
19
- ROBOT_SERVER_PID=$!
20
- echo "[entrypoint] robot-server pid=${ROBOT_SERVER_PID}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  fi
22
 
23
- # ここで Gradio/HTTP をフォアグラウンドで起動(exec が重要)
24
  echo "[entrypoint] starting main app..."
25
  exec python /home/user/app/main.py
 
 
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
+ # venv activate (あなたの app 用)
5
  if [ -f "/home/user/app/.venv/bin/activate" ]; then
6
  source /home/user/app/.venv/bin/activate
7
  fi
8
 
 
9
  export GRADIO_SERVER_NAME="${GRADIO_SERVER_NAME:-0.0.0.0}"
10
  export GRADIO_SERVER_PORT="${GRADIO_SERVER_PORT:-7860}"
11
  export PORT="${PORT:-7860}"
12
 
13
+ # robot-server 起動(ログをファイルにも吐く)
14
+ echo "[entrypoint] starting robot-server..."
15
+ (cd /root/opentrons && make -C robot-server dev-flex) > /tmp/robot-server.log 2>&1 &
16
+ ROBOT_SERVER_PID=$!
17
+ echo "[entrypoint] robot-server pid=${ROBOT_SERVER_PID}"
18
+
19
+ # 31950 が開くまで待つ(最大60秒)
20
+ echo "[entrypoint] waiting for robot-server (127.0.0.1:31950)..."
21
+ for i in {1..60}; do
22
+ if (echo > /dev/tcp/127.0.0.1/31950) >/dev/null 2>&1; then
23
+ echo "[entrypoint] robot-server is up"
24
+ break
25
+ fi
26
+
27
+ # robot-server が落ちてたらログを出して終了
28
+ if ! kill -0 "${ROBOT_SERVER_PID}" >/dev/null 2>&1; then
29
+ echo "[entrypoint] robot-server exited early. Last logs:"
30
+ tail -n 200 /tmp/robot-server.log || true
31
+ exit 1
32
+ fi
33
+
34
+ sleep 1
35
+ done
36
+
37
+ # 60秒待っても開かなければログを出して終了
38
+ if ! (echo > /dev/tcp/127.0.0.1/31950) >/dev/null 2>&1; then
39
+ echo "[entrypoint] robot-server did not start in time. Last logs:"
40
+ tail -n 200 /tmp/robot-server.log || true
41
+ exit 1
42
  fi
43
 
 
44
  echo "[entrypoint] starting main app..."
45
  exec python /home/user/app/main.py
46
+