74 lines
3.5 KiB
Bash
74 lines
3.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Script d'installation et de configuration de LOGIS en production
|
|
# Exécuter une seule fois sur le VPS en tant que l'utilisateur applicatif
|
|
# Usage : bash conf/setup_production.sh
|
|
|
|
set -euo pipefail
|
|
|
|
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
VENV="$BASE_DIR/venv"
|
|
LOG_DIR="/var/log/logis"
|
|
|
|
echo "==> Répertoire de l'application : $BASE_DIR"
|
|
|
|
# ── 1. Répertoires de logs ────────────────────────────────────────────────────
|
|
echo "==> Création du répertoire de logs…"
|
|
sudo mkdir -p "$LOG_DIR"
|
|
sudo chown "$USER:$USER" "$LOG_DIR"
|
|
sudo chmod 755 "$LOG_DIR"
|
|
|
|
# ── 2. Environnement virtuel Python ──────────────────────────────────────────
|
|
if [ ! -d "$VENV" ]; then
|
|
echo "==> Création du virtualenv…"
|
|
python3 -m venv "$VENV"
|
|
fi
|
|
echo "==> Installation des dépendances…"
|
|
"$VENV/bin/pip" install --upgrade pip
|
|
"$VENV/bin/pip" install -r "$BASE_DIR/requirements.txt"
|
|
|
|
# ── 3. Fichier .env de production ────────────────────────────────────────────
|
|
if [ ! -f "$BASE_DIR/.env" ]; then
|
|
echo "==> Copie de .env.example → .env (à personnaliser !)"
|
|
cp "$BASE_DIR/.env.example" "$BASE_DIR/.env"
|
|
echo ""
|
|
echo " ⚠ Éditez maintenant $BASE_DIR/.env avec vos vraies valeurs"
|
|
echo " (SECRET_KEY, EMAIL_*, ALLOWED_HOSTS, SITE_DOMAIN…)"
|
|
echo ""
|
|
fi
|
|
|
|
# ── 4. Migrations et fichiers statiques ──────────────────────────────────────
|
|
echo "==> Migrations…"
|
|
DJANGO_SETTINGS_MODULE=logis_project.settings.production \
|
|
"$VENV/bin/python" "$BASE_DIR/manage.py" migrate --noinput
|
|
|
|
echo "==> Fichiers statiques…"
|
|
DJANGO_SETTINGS_MODULE=logis_project.settings.production \
|
|
"$VENV/bin/python" "$BASE_DIR/manage.py" collectstatic --noinput
|
|
|
|
echo "==> Compilation des traductions…"
|
|
DJANGO_SETTINGS_MODULE=logis_project.settings.production \
|
|
"$VENV/bin/python" "$BASE_DIR/manage.py" compilemessages
|
|
|
|
# ── 5. Supervisor ────────────────────────────────────────────────────────────
|
|
echo "==> Installation du service Supervisor…"
|
|
sudo cp "$BASE_DIR/conf/supervisor.conf" /etc/supervisor/conf.d/logis.conf
|
|
sudo supervisorctl reread
|
|
sudo supervisorctl update
|
|
|
|
# ── 6. Nginx ─────────────────────────────────────────────────────────────────
|
|
echo "==> Installation de la configuration nginx…"
|
|
sudo cp "$BASE_DIR/conf/nginx.conf" /etc/nginx/sites-available/logis
|
|
if [ ! -f /etc/nginx/sites-enabled/logis ]; then
|
|
sudo ln -s /etc/nginx/sites-available/logis /etc/nginx/sites-enabled/logis
|
|
fi
|
|
sudo nginx -t && sudo systemctl reload nginx
|
|
|
|
# ── 7. Certbot SSL ────────────────────────────────────────────────────────────
|
|
echo ""
|
|
echo "==> Pour générer le certificat SSL, exécutez :"
|
|
echo " sudo certbot --nginx -d \$(grep SITE_DOMAIN $BASE_DIR/.env | cut -d= -f2)"
|
|
echo ""
|
|
|
|
echo "✓ Installation terminée."
|
|
echo " Créez un superutilisateur : $VENV/bin/python $BASE_DIR/manage.py createsuperuser"
|