Spaces:
Building
Building
File size: 965 Bytes
46257e1 8396a84 46257e1 |
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 |
#!/bin/bash
set -e
# Function to log messages with timestamp
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Function to check if a service is up
wait_for_service() {
local host=$1
local port=$2
local retries=30
local wait=2
log "Waiting for $host:$port to be available..."
for ((i=1;i<=retries;i++)); do
if nc -z "$host" "$port"; then
log "$host:$port is available."
return 0
else
log "Attempt $i/$retries: $host:$port not available. Retrying in $wait seconds..."
sleep "$wait"
fi
done
log "Error: $host:$port did not become available after $((retries * wait)) seconds."
exit 1
}
# Start TorchServe
log "Starting TorchServe..."
torchserve --start --ncs --ts-config /home/torchserve/model-store
# Wait until TorchServe is up and running
wait_for_service "localhost" 8080
# Start Gradio app
log "Starting Gradio application..."
python app.py |