Remove unused start.sh script

- Removed start.sh since process startup is handled by vidai.py
- vidai.py now includes proper backend readiness checking
- Simplified deployment by using single Python launcher
parent 03f65ee6
#!/bin/bash
# Video AI Startup Script (Cross-platform)
# Copyright (C) 2024 Stefy Lanza <stefy@sexhack.me>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Cross-platform startup script for Video AI Analysis Tool
# Launches all processes in the correct order
# Detect platform
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
IS_WINDOWS=1
PYTHON_CMD="python"
SLEEP_CMD="timeout"
else
IS_WINDOWS=0
PYTHON_CMD="python3"
SLEEP_CMD="sleep"
fi
# Read configuration to determine which backends to use
if [ -f "vidai/config.py" ]; then
# Try to get config values, fallback to defaults
ANALYSIS_BACKEND=$($PYTHON_CMD -c "from vidai.config import get_analysis_backend; print(get_analysis_backend())" 2>/dev/null || echo "cuda")
TRAINING_BACKEND=$($PYTHON_CMD -c "from vidai.config import get_training_backend; print(get_training_backend())" 2>/dev/null || echo "cuda")
else
ANALYSIS_BACKEND="cuda"
TRAINING_BACKEND="cuda"
fi
echo "Starting Video AI Analysis Tool on $(uname -s)..."
echo "Analysis backend: $ANALYSIS_BACKEND"
echo "Training backend: $TRAINING_BACKEND"
# Create result directory (cross-platform)
if [ $IS_WINDOWS -eq 1 ]; then
mkdir -p "%TEMP%/vidai_results" 2>/dev/null || true
else
mkdir -p /tmp/vidai_results
fi
# Function to start process and store PID
start_process() {
local name=$1
local cmd=$2
echo "Starting $name..."
if [ $IS_WINDOWS -eq 1 ]; then
# On Windows, use start command to run in background
start "$name" $cmd
# Note: Windows doesn't give us easy access to PIDs from batch files
echo "Started $name in background"
else
# On Unix-like systems
$cmd &
local pid=$!
eval "${name}_PID=$pid"
echo "Started $name (PID: $pid)"
fi
}
# Start backend
start_process "backend" "$PYTHON_CMD -m vidai.backend"
# Wait for backend to be ready
echo "Waiting for backend to be ready..."
if [ $IS_WINDOWS -eq 1 ]; then
# On Windows, just sleep
$SLEEP_CMD 3
else
# On Unix-like systems, check if socket exists
max_wait=10
for i in $(seq 1 $max_wait); do
if [ -S "/tmp/vidai_worker.sock" ]; then
echo "Backend is ready!"
break
fi
echo "Waiting for backend... ($i/$max_wait)"
$SLEEP_CMD 1
if [ $i -eq $max_wait ]; then
echo "Backend failed to start within $max_wait seconds"
exit 1
fi
done
fi
# Start workers with configured backends
start_process "analysis_worker" "$PYTHON_CMD -c \"from vidai.worker_analysis import worker_process; worker_process('$ANALYSIS_BACKEND')\""
start_process "training_worker" "$PYTHON_CMD -c \"from vidai.worker_training import worker_process; worker_process('$TRAINING_BACKEND')\""
$SLEEP_CMD 2
# Start web interface
start_process "web_interface" "$PYTHON_CMD -m vidai.web"
echo "All processes started!"
echo "Web interface available at http://localhost:5000"
echo "Press Ctrl+C to stop all processes"
# Wait for interrupt
if [ $IS_WINDOWS -eq 1 ]; then
echo "Press any key to stop..."
read -n 1
echo "Stopping processes..."
# On Windows, we can't easily kill background processes from batch
# User will need to manually close windows or use Task Manager
else
trap "echo 'Stopping all processes...'; kill \$WEB_PID \$TRAINING_PID \$ANALYSIS_PID \$BACKEND_PID 2>/dev/null; exit" INT
wait
fi
\ No newline at end of file
...@@ -252,6 +252,41 @@ Examples: ...@@ -252,6 +252,41 @@ Examples:
backend_cmd = [sys.executable, '-m', 'vidai.backend'] backend_cmd = [sys.executable, '-m', 'vidai.backend']
backend_proc = subprocess.Popen(backend_cmd) backend_proc = subprocess.Popen(backend_cmd)
# Wait for backend to be ready
import time
import socket
from vidai.compat import get_socket_path, is_unix_sockets_supported
print("Waiting for backend to be ready...")
max_wait = 15
for i in range(max_wait):
try:
if is_unix_sockets_supported():
# Check Unix socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(1)
sock.connect(get_socket_path('worker'))
sock.close()
print("Backend Unix socket is ready!")
break
else:
# Check TCP port
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
sock.connect((args.backend_host, args.backend_worker_port))
sock.close()
print("Backend TCP port is ready!")
break
except (FileNotFoundError, ConnectionRefusedError, OSError):
if i < max_wait - 1:
print(f"Waiting for backend... ({i+1}/{max_wait})")
time.sleep(1)
else:
print("Backend failed to start within timeout")
backend_proc.terminate()
backend_proc.wait()
sys.exit(1)
# Start analysis worker # Start analysis worker
analysis_cmd = [sys.executable, '-m', 'vidai.worker_analysis', args.analysis_backend] analysis_cmd = [sys.executable, '-m', 'vidai.worker_analysis', args.analysis_backend]
analysis_proc = subprocess.Popen(analysis_cmd) analysis_proc = subprocess.Popen(analysis_cmd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment