Files
Smartwave/orchestrateur/launch.sh
T
Ninluc 3753f57041
Build, push image, and notify Watchtower / build-image (push) Successful in 3m22s
Build, push image, and notify Watchtower / notify (push) Successful in 1m24s
Small things because fuck sd cards
2026-08-25 19:16:50 +02:00

55 lines
1.7 KiB
Bash

#!/bin/sh
set -eu
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
REPO_ROOT=$(dirname -- "$SCRIPT_DIR")
VENV_DIR="$SCRIPT_DIR/venv"
PYTHON_BIN="${PYTHON_BIN:-python3}"
PYTHON_SCRIPT="${1:-$SCRIPT_DIR/main.py}"
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements.txt"
if [ ! -f "$PYTHON_SCRIPT" ]; then
echo "Python script not found: $PYTHON_SCRIPT" >&2
exit 1
fi
# 1. On définit proprement le PYTHONPATH pour tout le script
export PYTHONPATH="$REPO_ROOT"
cd "$SCRIPT_DIR"
# 2. On lance Docker en arrière-plan
echo "Démarrage des conteneurs Docker..."
docker compose up -d --remove-orphans
# 3. Gestion propre de l'environnement virtuel Python (contourne PEP 668)
if [ ! -d "$VENV_DIR" ]; then
echo "Création de l'environnement virtuel Python..."
"$PYTHON_BIN" -m venv "$VENV_DIR"
fi
# Utiliser le pip/python du venv
VENV_PYTHON="$VENV_DIR/bin/python"
VENV_PIP="$VENV_DIR/bin/pip"
if [ -f "$REQUIREMENTS_FILE" ]; then
echo "Vérification et installation des dépendances dans le venv..."
"$VENV_PIP" install --upgrade pip >/dev/null 2>&1 || true
"$VENV_PIP" install -r "$REQUIREMENTS_FILE"
fi
# 4. Sécurité anti-conflit : On vérifie si Docker n'a pas verrouillé le port USB de la LA66
PORT="/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0"
if [ -e "$PORT" ]; then
echo "Vérification de la disponibilité du port série..."
if lsof "$PORT" >/dev/null 2>&1; then
echo "Le port série est occupé ! Libération en cours..."
fuser -k "$PORT" || true
sleep 1
fi
fi
# 5. Lancement propre du script Python via le venv
echo "Launching Python script: $PYTHON_SCRIPT"
cd "$SCRIPT_DIR"
exec "$VENV_PYTHON" "$PYTHON_SCRIPT"