#!/bin/bash set -e cd /home/container echo "======================================" echo "GooDrive" echo "======================================" # -------------------------------------- # Mise à jour du projet # -------------------------------------- if [ ! -d ".git" ]; then echo "Dépôt Git absent → clonage..." git clone https://gitea.louismazin.ovh/LouisMazin/GooDrive.git /tmp/goodrive cp -a /tmp/goodrive/. /home/container/ rm -rf /tmp/goodrive else echo "Mise à jour du dépôt Git..." git fetch origin git reset --hard origin/main fi echo "Git : $(git rev-parse --short HEAD)" # -------------------------------------- # Backend # -------------------------------------- cd /home/container/backend python3 manage.py check echo "Démarrage Django sur :1035" python3 manage.py migrate --noinput python manage.py ensure_admin # Purge au démarrage puis une fois par heure (éléments de plus de 5 jours). trash_cleanup_loop() { while true; do python3 manage.py cleanup_trash --days 5 || echo "Échec du nettoyage de la corbeille (nouvel essai dans 1 heure)." >&2 sleep 3600 done } trash_cleanup_loop & CLEANER_PID=$! python3 manage.py runserver 0.0.0.0:1035 & BACKEND_PID=$! # -------------------------------------- # Frontend # -------------------------------------- cd /home/container/frontend echo "Installation des dépendances frontend..." npm ci echo "Build React..." npm run build echo "Démarrage frontend sur :1034" npm run preview -- --host 0.0.0.0 --port 1034 & FRONTEND_PID=$! # -------------------------------------- # Arrêt propre # -------------------------------------- cleanup() { echo "Arrêt des applications..." kill "$BACKEND_PID" 2>/dev/null || true kill "$FRONTEND_PID" 2>/dev/null || true kill "$CLEANER_PID" 2>/dev/null || true wait "$BACKEND_PID" 2>/dev/null || true wait "$FRONTEND_PID" 2>/dev/null || true wait "$CLEANER_PID" 2>/dev/null || true } trap cleanup SIGTERM SIGINT EXIT echo "======================================" echo " Frontend : :1034" echo " Backend : :1035" echo "======================================" wait -n "$BACKEND_PID" "$FRONTEND_PID"