#!/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/user/torchserve/config.properties # Wait until TorchServe is up and running wait_for_service "localhost" 8080 # Start Gradio app log "Starting Gradio application..." python app.py