-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·50 lines (39 loc) · 1.17 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·50 lines (39 loc) · 1.17 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
#!/bin/bash
cd "$(dirname "$0")"
PIDFILE="/tmp/easy-ocr.pid"
EXIT_FLAG="/tmp/easy-ocr.exit"
cleanup() {
rm -f "$PIDFILE" "$EXIT_FLAG"
pkill -P $$ 2>/dev/null
exit 0
}
trap cleanup SIGINT SIGTERM
if [ -f "$EXIT_FLAG" ]; then
rm -f "$EXIT_FLAG"
fi
echo "Starting EasyOCR API (Ctrl+C to stop)..."
while [ ! -f "$EXIT_FLAG" ]; do
cd "$(dirname "$0")"
PYTHONPATH="$PWD/src:$PYTHONPATH" uv run python -c "
import sys, os, warnings, logging, uvicorn
warnings.filterwarnings('ignore')
os.environ.update({'TF_CPP_MIN_LOG_LEVEL': '3'})
from main import app
from config import HOST, PORT, DEVICE
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
for n in ['uvicorn.error', 'uvicorn.access']:
logging.getLogger(n).setLevel(logging.CRITICAL)
logging.info(f'Device: {DEVICE} | Server: {HOST}:{PORT}')
uvicorn.run(app, host=HOST, port=PORT, timeout_keep_alive=300, limit_max_requests=1000, log_level='error')
" &
PID=$!
echo $PID > "$PIDFILE"
wait $PID
EXIT_CODE=$?
if [ -f "$EXIT_FLAG" ]; then
break
fi
echo "Server stopped (exit code: $EXIT_CODE), restarting in 2s..."
sleep 2
done
cleanup