88 lines
2.8 KiB
Bash
88 lines
2.8 KiB
Bash
#!/usr/bin/env bash
|
|
# DictIA ASR Proxy — Setup script
|
|
# Installs the GCP GPU proxy for cloud deployments.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
INSTALL_DIR="${ASR_PROXY_DIR:-$SCRIPT_DIR}"
|
|
SERVICE_USER="${ASR_PROXY_USER:-$(whoami)}"
|
|
|
|
echo "=== DictIA ASR Proxy Setup ==="
|
|
echo "Install directory: $INSTALL_DIR"
|
|
echo "Service user: $SERVICE_USER"
|
|
echo
|
|
|
|
# 1. Create virtual environment
|
|
if [ ! -d "$INSTALL_DIR/venv" ]; then
|
|
echo "[1/4] Creating Python virtual environment..."
|
|
python3 -m venv "$INSTALL_DIR/venv"
|
|
else
|
|
echo "[1/4] Virtual environment already exists."
|
|
fi
|
|
|
|
# 2. Install dependencies
|
|
echo "[2/4] Installing Python dependencies..."
|
|
"$INSTALL_DIR/venv/bin/pip" install --quiet --upgrade pip
|
|
"$INSTALL_DIR/venv/bin/pip" install --quiet -r "$INSTALL_DIR/requirements.txt"
|
|
|
|
# 3. GCP credentials
|
|
if [ ! -f "$INSTALL_DIR/gcp-credentials.json" ]; then
|
|
echo "[3/4] GCP credentials not found."
|
|
echo " Place your GCP service account or OAuth credentials at:"
|
|
echo " $INSTALL_DIR/gcp-credentials.json"
|
|
echo
|
|
echo " For service account: download JSON from GCP Console > IAM > Service Accounts"
|
|
echo " For user credentials: run 'gcloud auth application-default login' and copy the file"
|
|
echo
|
|
read -rp " Path to credentials file (or press Enter to skip): " CREDS_PATH
|
|
if [ -n "$CREDS_PATH" ] && [ -f "$CREDS_PATH" ]; then
|
|
cp "$CREDS_PATH" "$INSTALL_DIR/gcp-credentials.json"
|
|
chmod 600 "$INSTALL_DIR/gcp-credentials.json"
|
|
echo " Credentials copied."
|
|
else
|
|
echo " Skipped. You must add credentials before starting the proxy."
|
|
fi
|
|
else
|
|
echo "[3/4] GCP credentials found."
|
|
fi
|
|
|
|
# 4. Install systemd service
|
|
echo "[4/4] Installing systemd service..."
|
|
SERVICE_FILE="/etc/systemd/system/asr-proxy.service"
|
|
|
|
cat > /tmp/asr-proxy.service <<UNIT
|
|
[Unit]
|
|
Description=DictIA ASR Proxy - GPU Auto-Start/Stop for WhisperX
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=$SERVICE_USER
|
|
Restart=always
|
|
RestartSec=10
|
|
WorkingDirectory=$INSTALL_DIR
|
|
ExecStart=$INSTALL_DIR/venv/bin/python proxy.py
|
|
Environment=GOOGLE_APPLICATION_CREDENTIALS=$INSTALL_DIR/gcp-credentials.json
|
|
Environment=STATS_FILE=$INSTALL_DIR/usage-stats.json
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
UNIT
|
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
cp /tmp/asr-proxy.service "$SERVICE_FILE"
|
|
systemctl daemon-reload
|
|
systemctl enable asr-proxy.service
|
|
echo " Service installed and enabled."
|
|
echo " Start with: systemctl start asr-proxy"
|
|
else
|
|
echo " Run as root to install systemd service, or copy manually:"
|
|
echo " sudo cp /tmp/asr-proxy.service $SERVICE_FILE"
|
|
echo " sudo systemctl daemon-reload && sudo systemctl enable asr-proxy"
|
|
fi
|
|
|
|
echo
|
|
echo "=== Setup complete ==="
|
|
echo "Dashboard: http://localhost:9090"
|
|
echo "Health: http://localhost:9090/health"
|