forked from TeamBreakerr/douyin-chat-export
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
61 lines (54 loc) · 1.84 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
61 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -e
MODE="${MODE:-all}"
UVICORN_PID=""
SCHEDULER_PID=""
cleanup() {
echo "[entrypoint] Shutting down..."
[ -n "$UVICORN_PID" ] && kill "$UVICORN_PID" 2>/dev/null
[ -n "$SCHEDULER_PID" ] && kill "$SCHEDULER_PID" 2>/dev/null
wait
exit 0
}
trap cleanup SIGTERM SIGINT
# Ensure DB schema exists
python -c "from extractor.models import init_db; init_db()"
echo "[entrypoint] MODE=$MODE"
# Start web server
if [ "$MODE" = "web" ] || [ "$MODE" = "all" ]; then
if [ "$MODE" = "web" ]; then
# Foreground — this is the only service
echo "[entrypoint] Starting web server (foreground)..."
exec python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000
else
# Background — scraper/scheduler will also run
echo "[entrypoint] Starting web server (background)..."
python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 &
UVICORN_PID=$!
sleep 1
fi
fi
# Start scraper / scheduler
if [ "$MODE" = "scraper" ] || [ "$MODE" = "all" ]; then
if [ -n "$SCRAPER_SCHEDULE" ]; then
echo "[entrypoint] Starting scheduler (schedule: $SCRAPER_SCHEDULE)..."
python -u scheduler.py &
SCHEDULER_PID=$!
else
if [ "$MODE" = "scraper" ]; then
# Run once and exit
echo "[entrypoint] Running scraper once..."
CMD="python -u extract.py"
[ "$SCRAPER_INCREMENTAL" = "true" ] && CMD="$CMD --incremental"
[ -n "$SCRAPER_FILTER" ] && CMD="$CMD --filter \"$SCRAPER_FILTER\""
eval $CMD
echo "[entrypoint] Scraper finished."
exit 0
fi
# MODE=all without schedule: just start web, no auto-scrape
# (scraping can be triggered from control panel)
fi
fi
# Wait for background processes
echo "[entrypoint] Services running. Waiting..."
wait