mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
VPS flow for a root clone of PyQuest: server_setup, server_update, server_manage; drop ssh/sudo push scripts
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Déploie dist/ sur un VPS : envoi dans un dossier de version (releases/<date>-<commit>), puis bascule
|
||||
# atomique du lien « current » vers cette version. Le site reste servi sans coupure ; on peut revenir en
|
||||
# arrière (--rollback). Aucun secret ici : l'hôte vient de l'environnement, l'authentification de ta clé SSH.
|
||||
#
|
||||
# DEPLOY_HOST=utilisateur@vps.example.org ./scripts/deploy.sh [--dry-run]
|
||||
# DEPLOY_HOST=utilisateur@vps.example.org ./scripts/deploy.sh --rollback
|
||||
# DEPLOY_HOST=utilisateur@vps.example.org ./scripts/deploy.sh --backend [--no-restart]
|
||||
#
|
||||
# --backend : envoie le code du backend Django (dossier backend/) dans DEPLOY_BACKEND_PATH puis redémarre le service
|
||||
# (« sudo -n systemctl restart pyquest » : voir deploy/remote_setup.sh qui autorise cette seule commande). Au
|
||||
# redémarrage, systemd applique les migrations et collecte les fichiers statiques.
|
||||
#
|
||||
# Variables : DEPLOY_HOST (obligatoire), DEPLOY_PATH (défaut /var/www/pyquest), DEPLOY_KEEP (défaut 3),
|
||||
# DEPLOY_BACKEND_PATH (défaut /opt/pyquest/backend), DEPLOY_SSH (défaut « ssh -o BatchMode=yes »).
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
HOST="${DEPLOY_HOST:-}"
|
||||
REMOTE_PATH="${DEPLOY_PATH:-/var/www/pyquest}"
|
||||
KEEP="${DEPLOY_KEEP:-3}"
|
||||
BACKEND_PATH="${DEPLOY_BACKEND_PATH:-/opt/pyquest/backend}"
|
||||
SSH="${DEPLOY_SSH:-ssh -o BatchMode=yes}"
|
||||
RESTART=1
|
||||
MODE="deploy"
|
||||
DRY_RUN=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "${arg}" in
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
--rollback) MODE="rollback" ;;
|
||||
--backend) MODE="backend" ;;
|
||||
--no-restart) RESTART=0 ;;
|
||||
-h|--help) sed -n '2,16p' "${BASH_SOURCE[0]}"; exit 0 ;;
|
||||
*) echo "Option inconnue : ${arg}" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Ces valeurs sont insérées dans des commandes distantes : on n'accepte que des caractères sûrs.
|
||||
[[ "${HOST}" =~ ^[A-Za-z0-9_.@:-]+$ ]] || { echo "DEPLOY_HOST manquant ou invalide (ex. utilisateur@vps.example.org)" >&2; exit 2; }
|
||||
[[ "${REMOTE_PATH}" =~ ^/[A-Za-z0-9_./-]{3,}$ ]] || { echo "DEPLOY_PATH doit être un chemin absolu simple (ex. /var/www/pyquest)" >&2; exit 2; }
|
||||
[[ "${BACKEND_PATH}" =~ ^/[A-Za-z0-9_./-]{3,}$ ]] || { echo "DEPLOY_BACKEND_PATH doit être un chemin absolu simple" >&2; exit 2; }
|
||||
[[ "${KEEP}" =~ ^[1-9][0-9]*$ ]] || { echo "DEPLOY_KEEP doit être un entier >= 1" >&2; exit 2; }
|
||||
|
||||
remote() {
|
||||
if [[ "${DRY_RUN}" == 1 ]]; then
|
||||
echo "[dry-run] ssh ${HOST} $*"
|
||||
else
|
||||
# shellcheck disable=SC2086 # ${SSH} contient volontairement plusieurs mots
|
||||
${SSH} "${HOST}" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "${MODE}" == "rollback" ]]; then
|
||||
# Bascule vers la version précédente (la plus récente avant celle qui est en ligne).
|
||||
remote "set -e; cd '${REMOTE_PATH}'; current=\$(basename \"\$(readlink current)\"); \
|
||||
previous=\$(ls -1 releases | sort | grep -B1 -x \"\$current\" | head -n1); \
|
||||
[ -n \"\$previous\" ] && [ \"\$previous\" != \"\$current\" ] || { echo 'Aucune version précédente.' >&2; exit 1; }; \
|
||||
ln -sfn \"releases/\$previous\" current.tmp && mv -Tf current.tmp current; echo \"Retour à \$previous\""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "${MODE}" == "backend" ]]; then
|
||||
[[ -f "${ROOT}/backend/manage.py" ]] || { echo "backend/manage.py introuvable." >&2; exit 1; }
|
||||
echo "Envoi du backend vers ${HOST}:${BACKEND_PATH}"
|
||||
remote "mkdir -p '${BACKEND_PATH}'"
|
||||
BACK=(rsync -az --delete --chmod=D755,F644 -e "${SSH}"
|
||||
--exclude='__pycache__/' --exclude='*.pyc' --exclude='db.sqlite3' --exclude='staticfiles/' --exclude='.venv/' --exclude='venv/' --exclude='*.mo')
|
||||
[[ "${DRY_RUN}" == 1 ]] && BACK+=(--dry-run --itemize-changes)
|
||||
"${BACK[@]}" "${ROOT}/backend/" "${HOST}:${BACKEND_PATH}/"
|
||||
if [[ "${RESTART}" == 1 ]]; then
|
||||
# Une seule commande sudo autorisée sans mot de passe (voir deploy/remote_setup.sh) ; sinon on le dit.
|
||||
remote "sudo -n systemctl restart pyquest" || echo "Redémarrage impossible sans mot de passe : lance « sudo systemctl restart pyquest » sur le VPS." >&2
|
||||
fi
|
||||
echo "Backend envoyé. Migrations et statiques sont appliqués au démarrage du service."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
[[ -f "${ROOT}/dist/index.html" ]] || { echo "dist/ est absent : lance d'abord « make build »." >&2; exit 1; }
|
||||
[[ -f "${ROOT}/dist/vendor/pyodide/pyodide.asm.wasm" ]] || { echo "Pyodide manque dans dist/ : « make vendor-pyodide » puis « make build »." >&2; exit 1; }
|
||||
|
||||
COMMIT="$(git -C "${ROOT}" rev-parse --short HEAD 2>/dev/null || echo nogit)"
|
||||
git -C "${ROOT}" diff --quiet HEAD 2>/dev/null || COMMIT="${COMMIT}-dirty"
|
||||
RELEASE="$(date +%Y%m%d%H%M%S)-${COMMIT}"
|
||||
TARGET="${REMOTE_PATH}/releases/${RELEASE}"
|
||||
|
||||
echo "Déploiement de dist/ ($(du -sh "${ROOT}/dist" | cut -f1)) vers ${HOST}:${TARGET}"
|
||||
remote "mkdir -p '${REMOTE_PATH}/releases'"
|
||||
|
||||
RSYNC=(rsync -az --delete --chmod=D755,F644 -e "${SSH}")
|
||||
# Réutilise (liens physiques) les fichiers inchangés de la version en ligne : envoi plus rapide, moins de disque.
|
||||
# shellcheck disable=SC2086
|
||||
if ${SSH} "${HOST}" "test -d '${REMOTE_PATH}/current'" 2>/dev/null; then
|
||||
RSYNC+=(--link-dest="${REMOTE_PATH}/current/")
|
||||
fi
|
||||
[[ "${DRY_RUN}" == 1 ]] && RSYNC+=(--dry-run --itemize-changes)
|
||||
"${RSYNC[@]}" "${ROOT}/dist/" "${HOST}:${TARGET}/"
|
||||
|
||||
# Bascule atomique : création d'un lien temporaire puis renommage (jamais de lien cassé).
|
||||
remote "set -e; cd '${REMOTE_PATH}'; ln -sfn 'releases/${RELEASE}' current.tmp && mv -Tf current.tmp current"
|
||||
# Ne garde que les KEEP dernières versions (la version en ligne est toujours la plus récente).
|
||||
remote "cd '${REMOTE_PATH}/releases' && ls -1 | sort | head -n -${KEEP} | xargs -r rm -rf --"
|
||||
|
||||
echo "En ligne : ${RELEASE} (retour arrière : DEPLOY_HOST=${HOST} $0 --rollback)"
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
# Lance une commande « manage.py » de Django avec la configuration de production (/etc/pyquest/env) et l'environnement
|
||||
# Python du serveur. À utiliser SUR LE VPS, en root, depuis le dépôt cloné :
|
||||
#
|
||||
# ./scripts/server_manage.sh createsuperuser # premier administrateur
|
||||
# ./scripts/server_manage.sh create_author ada # compte auteur (--reset, --admin)
|
||||
# ./scripts/server_manage.sh migrate | check | shell
|
||||
#
|
||||
# Le fichier d'environnement est lu ligne à ligne (pas de « source ») : un mot de passe contenant $ ou des espaces ne
|
||||
# pose pas de problème.
|
||||
set -euo pipefail
|
||||
|
||||
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
ENV_FILE="${PYQUEST_ENV_FILE:-/etc/pyquest/env}"
|
||||
VENV="${REPO}/.venv-prod"
|
||||
|
||||
[[ -r "${ENV_FILE}" ]] || { echo "Impossible de lire ${ENV_FILE} (root requis, installation faite ?)." >&2; exit 1; }
|
||||
[[ -x "${VENV}/bin/python" ]] || { echo "${VENV} absent : lancer ./deploy/server_setup.sh d'abord." >&2; exit 1; }
|
||||
[[ $# -ge 1 ]] || { sed -n '2,10p' "${BASH_SOURCE[0]}"; exit 2; }
|
||||
|
||||
while IFS= read -r line; do
|
||||
[[ "${line}" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]] && export "${line?}"
|
||||
done < "${ENV_FILE}"
|
||||
|
||||
cd "${REPO}/backend"
|
||||
exec "${VENV}/bin/python" manage.py "$@"
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env bash
|
||||
# Met à jour le site et le backend sur le VPS, EN ROOT, depuis le dépôt cloné : récupère la dernière version (git),
|
||||
# construit le site, le publie par bascule atomique du lien « current » (releases/<date>-<commit>), met à jour les
|
||||
# dépendances du backend, redémarre le service (migrations et statiques appliqués au démarrage), puis contrôle le site.
|
||||
#
|
||||
# ./scripts/server_update.sh # tout
|
||||
# ./scripts/server_update.sh --rollback # revient à la version précédente du site
|
||||
# Options : --no-pull --no-build --no-restart --no-check --dry-run
|
||||
#
|
||||
# Variables : PYQUEST_WEB_ROOT (défaut /var/www/pyquest), PYQUEST_KEEP (versions conservées, défaut 3),
|
||||
# PYQUEST_ENV_FILE (défaut /etc/pyquest/env), PYQUEST_SERVICE (défaut pyquest).
|
||||
set -euo pipefail
|
||||
|
||||
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
WEB_ROOT="${PYQUEST_WEB_ROOT:-/var/www/pyquest}"
|
||||
KEEP="${PYQUEST_KEEP:-3}"
|
||||
ENV_FILE="${PYQUEST_ENV_FILE:-/etc/pyquest/env}"
|
||||
SERVICE="${PYQUEST_SERVICE:-pyquest}"
|
||||
VENV="${REPO}/.venv-prod"
|
||||
PULL=1; BUILD=1; RESTART=1; CHECK=1; DRY_RUN=0; ROLLBACK=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "${arg}" in
|
||||
--no-pull) PULL=0 ;;
|
||||
--no-build) BUILD=0 ;;
|
||||
--no-restart) RESTART=0 ;;
|
||||
--no-check) CHECK=0 ;;
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
--rollback) ROLLBACK=1 ;;
|
||||
-h|--help) sed -n '2,11p' "${BASH_SOURCE[0]}"; exit 0 ;;
|
||||
*) echo "Option inconnue : ${arg}" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ "${WEB_ROOT}" =~ ^/[A-Za-z0-9_./-]{3,}$ ]] || { echo "PYQUEST_WEB_ROOT doit être un chemin absolu simple" >&2; exit 2; }
|
||||
[[ "${KEEP}" =~ ^[1-9][0-9]*$ ]] || { echo "PYQUEST_KEEP doit être un entier >= 1" >&2; exit 2; }
|
||||
# PYQUEST_ALLOW_NON_ROOT : réservé aux tests automatiques (dossiers temporaires).
|
||||
[[ "${DRY_RUN}" == 1 || "${EUID}" -eq 0 || -n "${PYQUEST_ALLOW_NON_ROOT:-}" ]] || { echo "À lancer en root." >&2; exit 1; }
|
||||
|
||||
step() { printf '\n==> %s\n' "$*"; }
|
||||
run() {
|
||||
if [[ "${DRY_RUN}" == 1 ]]; then printf '[dry-run] %s\n' "$*"; else "$@"; fi
|
||||
}
|
||||
|
||||
if [[ "${ROLLBACK}" == 1 ]]; then
|
||||
step "Retour à la version précédente du site"
|
||||
current="$(basename "$(readlink "${WEB_ROOT}/current")")"
|
||||
previous="$(ls -1 "${WEB_ROOT}/releases" | sort | grep -B1 -x "${current}" | head -n1 || true)"
|
||||
[[ -n "${previous}" && "${previous}" != "${current}" ]] || { echo "Aucune version précédente." >&2; exit 1; }
|
||||
run ln -sfn "releases/${previous}" "${WEB_ROOT}/current.tmp"
|
||||
run mv -Tf "${WEB_ROOT}/current.tmp" "${WEB_ROOT}/current"
|
||||
echo "Retour à ${previous}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "${PULL}" == 1 ]]; then
|
||||
step "Récupération de la dernière version (git pull --ff-only)"
|
||||
# --ff-only : jamais de fusion surprise sur le serveur ; un dépôt modifié localement est signalé.
|
||||
git -C "${REPO}" diff --quiet HEAD || { echo "Le dépôt contient des modifications locales : les annuler ou les mettre de côté (git status)." >&2; exit 1; }
|
||||
run git -C "${REPO}" pull --ff-only
|
||||
fi
|
||||
COMMIT="$(git -C "${REPO}" rev-parse --short HEAD 2>/dev/null || echo nogit)"
|
||||
|
||||
if [[ "${BUILD}" == 1 ]]; then
|
||||
step "Moteur Python (Pyodide) et construction du site"
|
||||
run "${REPO}/scripts/vendor_pyodide.sh"
|
||||
run python3 "${REPO}/scripts/build.py"
|
||||
fi
|
||||
[[ "${DRY_RUN}" == 1 || -f "${REPO}/dist/index.html" ]] || { echo "dist/ est absent : relancer sans --no-build." >&2; exit 1; }
|
||||
[[ "${DRY_RUN}" == 1 || -f "${REPO}/dist/vendor/pyodide/pyodide.asm.wasm" ]] || { echo "Pyodide manque dans dist/." >&2; exit 1; }
|
||||
|
||||
RELEASE="$(date +%Y%m%d%H%M%S)-${COMMIT}"
|
||||
TARGET="${WEB_ROOT}/releases/${RELEASE}"
|
||||
step "Publication : ${TARGET}"
|
||||
run mkdir -p "${WEB_ROOT}/releases"
|
||||
RSYNC=(rsync -a --delete --chmod=D755,F644)
|
||||
[[ -d "${WEB_ROOT}/current" ]] && RSYNC+=(--link-dest="${WEB_ROOT}/current/")
|
||||
run "${RSYNC[@]}" "${REPO}/dist/" "${TARGET}/"
|
||||
# Bascule atomique : lien temporaire puis renommage (jamais de lien cassé).
|
||||
run ln -sfn "releases/${RELEASE}" "${WEB_ROOT}/current.tmp"
|
||||
run mv -Tf "${WEB_ROOT}/current.tmp" "${WEB_ROOT}/current"
|
||||
# Ne garde que les KEEP dernières versions.
|
||||
if [[ "${DRY_RUN}" == 0 ]]; then
|
||||
(cd "${WEB_ROOT}/releases" && ls -1 | sort | head -n -"${KEEP}" | xargs -r rm -rf --)
|
||||
fi
|
||||
|
||||
if [[ -x "${VENV}/bin/pip" ]]; then
|
||||
step "Dépendances du backend"
|
||||
run "${VENV}/bin/pip" install --quiet -r "${REPO}/backend/requirements-prod.txt"
|
||||
else
|
||||
echo "(pas d'environnement ${VENV} : backend non installé, ./deploy/server_setup.sh d'abord)"
|
||||
RESTART=0
|
||||
fi
|
||||
|
||||
if [[ "${RESTART}" == 1 ]]; then
|
||||
step "Redémarrage du service ${SERVICE} (migrations et statiques appliqués au démarrage)"
|
||||
run systemctl restart "${SERVICE}"
|
||||
if [[ "${DRY_RUN}" == 0 ]]; then
|
||||
sleep 3
|
||||
systemctl is-active --quiet "${SERVICE}" || { echo "Le service ${SERVICE} ne démarre pas : journalctl -u ${SERVICE} -n 50" >&2; exit 1; }
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${CHECK}" == 1 && "${DRY_RUN}" == 0 && -r "${ENV_FILE}" ]]; then
|
||||
ORIGIN="$(grep -E '^PYQUEST_ORIGIN=' "${ENV_FILE}" | tail -n1 | cut -d= -f2- || true)"
|
||||
if [[ -n "${ORIGIN}" ]]; then
|
||||
step "Contrôle du site publié (${ORIGIN})"
|
||||
"${REPO}/scripts/check_deploy.sh" "${ORIGIN}" || echo "Des contrôles ont échoué : voir ci-dessus (retour arrière : $0 --rollback)." >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "En ligne : ${RELEASE} (retour arrière du site : $0 --rollback)"
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Première installation sur un VPS, depuis ta machine : envoie le code du backend, les fichiers de déploiement et
|
||||
# nginx/, puis exécute deploy/remote_setup.sh en root sur le VPS (sudo, mot de passe demandé si besoin).
|
||||
#
|
||||
# DEPLOY_HOST=utilisateur@vps.example.org ./scripts/vps_bootstrap.sh --domain pyquest.example.org [--certbot mail] [--dry-run]
|
||||
#
|
||||
# Recommandé : commencer par --dry-run (n'écrit rien sur le VPS, affiche ce qui serait fait).
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
HOST="${DEPLOY_HOST:-}"
|
||||
SSH="${DEPLOY_SSH:-ssh}"
|
||||
DOMAIN=""
|
||||
EXTRA=()
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--domain) DOMAIN="${2:-}"; shift 2 ;;
|
||||
--certbot) EXTRA+=(--certbot "${2:-}"); shift 2 ;;
|
||||
--dry-run) EXTRA+=(--dry-run); shift ;;
|
||||
-h|--help) sed -n '2,8p' "${BASH_SOURCE[0]}"; exit 0 ;;
|
||||
*) echo "Option inconnue : $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
[[ "${HOST}" =~ ^[A-Za-z0-9_.@:-]+$ ]] || { echo "DEPLOY_HOST manquant ou invalide (ex. utilisateur@vps.example.org)" >&2; exit 2; }
|
||||
[[ "${DOMAIN}" =~ ^[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]] || { echo "--domain manquant ou invalide" >&2; exit 2; }
|
||||
DEPLOY_USER="${HOST%%@*}"
|
||||
[[ "${HOST}" == *@* ]] || { echo "DEPLOY_HOST doit contenir l'utilisateur (utilisateur@hote)" >&2; exit 2; }
|
||||
|
||||
echo "1/3 Envoi du code du backend"
|
||||
"${ROOT}/scripts/deploy.sh" --backend --no-restart
|
||||
|
||||
echo "2/3 Envoi des fichiers d'installation"
|
||||
STAGE="/tmp/pyquest-setup"
|
||||
# shellcheck disable=SC2086
|
||||
${SSH} "${HOST}" "rm -rf '${STAGE}' && mkdir -p '${STAGE}'"
|
||||
rsync -az -e "${SSH}" "${ROOT}/deploy/" "${HOST}:${STAGE}/deploy/"
|
||||
rsync -az -e "${SSH}" "${ROOT}/nginx/" "${HOST}:${STAGE}/nginx/"
|
||||
# shellcheck disable=SC2086
|
||||
${SSH} "${HOST}" "mkdir -p '${STAGE}/scripts'"
|
||||
rsync -az -e "${SSH}" "${ROOT}/scripts/backup_db.sh" "${HOST}:${STAGE}/scripts/"
|
||||
|
||||
echo "3/3 Installation sur le VPS (sudo)"
|
||||
# shellcheck disable=SC2086
|
||||
${SSH} -t "${HOST}" "sudo bash '${STAGE}/deploy/remote_setup.sh' --domain '${DOMAIN}' --deploy-user '${DEPLOY_USER}' ${EXTRA[*]:-}"
|
||||
+14
-10
@@ -1,10 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# Diagnostic en LECTURE SEULE d'un serveur PyQuest, à lancer depuis ta machine :
|
||||
# ssh utilisateur@vps.example.org 'bash -s' < scripts/vps_doctor.sh
|
||||
# (ou directement sur le VPS). Ne modifie rien et n'affiche aucun secret. Utile pour reprendre un déploiement.
|
||||
# Diagnostic en LECTURE SEULE d'un serveur PyQuest, à lancer SUR LE VPS (de préférence en root) depuis le dépôt cloné :
|
||||
# cd /opt/PyQuest && ./scripts/vps_doctor.sh
|
||||
# Ne modifie rien et n'affiche aucun secret. Utile pour reprendre un déploiement.
|
||||
set -uo pipefail
|
||||
|
||||
FAILED=0
|
||||
REPO="${PYQUEST_REPO:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." 2>/dev/null && pwd)}"
|
||||
[[ -f "${REPO}/backend/manage.py" ]] || REPO=/opt/PyQuest
|
||||
VENV="${REPO}/.venv-prod"
|
||||
ok() { printf ' ok %s\n' "$1"; }
|
||||
ko() { printf ' ÉCHEC %s\n' "$1"; FAILED=1; }
|
||||
info() { printf ' info %s\n' "$1"; }
|
||||
@@ -21,7 +24,7 @@ if command -v nginx >/dev/null; then
|
||||
ok "nginx ${version}"
|
||||
major="${version%%.*}"; minor="$(echo "${version}" | cut -d. -f2)"
|
||||
if (( major > 1 || (major == 1 && minor >= 25) )); then ok "http2 on; pris en charge"; else info "nginx < 1.25.1 : utiliser « listen 443 ssl http2; »"; fi
|
||||
if as_root nginx -t >/dev/null 2>&1; then ok "configuration valide (nginx -t)"; else info "nginx -t non vérifiable ou en échec (droits root requis) : lance « sudo nginx -t »"; fi
|
||||
if as_root nginx -t >/dev/null 2>&1; then ok "configuration valide (nginx -t)"; else info "nginx -t non vérifiable ou en échec (droits root requis) : lance « nginx -t »"; fi
|
||||
systemctl is-active --quiet nginx && ok "service nginx actif" || ko "service nginx inactif"
|
||||
else
|
||||
ko "nginx n'est pas installé"
|
||||
@@ -30,20 +33,21 @@ fi
|
||||
[[ -f /etc/nginx/snippets/pyquest-author-headers.conf ]] && ok "extrait pyquest-author-headers.conf installé" || ko "extrait pyquest-author-headers.conf manquant"
|
||||
|
||||
echo "Site statique"
|
||||
WEB=/var/www/pyquest
|
||||
WEB="${PYQUEST_WEB_ROOT:-/var/www/pyquest}"
|
||||
if [[ -L "${WEB}/current" ]]; then
|
||||
ok "current -> $(readlink "${WEB}/current")"
|
||||
[[ -f "${WEB}/current/index.html" ]] && ok "index.html présent" || ko "index.html absent dans current"
|
||||
[[ -f "${WEB}/current/vendor/pyodide/pyodide.asm.wasm" ]] && ok "moteur Python (Pyodide) présent" || ko "Pyodide absent : make vendor-pyodide puis make deploy"
|
||||
[[ -f "${WEB}/current/vendor/pyodide/pyodide.asm.wasm" ]] && ok "moteur Python (Pyodide) présent" || ko "Pyodide absent : ./scripts/server_update.sh"
|
||||
info "versions conservées : $(ls -1 "${WEB}/releases" 2>/dev/null | wc -l)"
|
||||
else
|
||||
ko "${WEB}/current absent : aucun déploiement du site (make deploy)"
|
||||
ko "${WEB}/current absent : site non publié (./scripts/server_update.sh)"
|
||||
fi
|
||||
[[ -d "${WEB}/static/admin" ]] && ok "fichiers statiques de l'administration présents" || info "statiques de l'administration absents (créés au démarrage du service)"
|
||||
|
||||
echo "Backend Django"
|
||||
[[ -x /opt/pyquest/venv/bin/gunicorn ]] && ok "environnement Python et gunicorn installés" || ko "/opt/pyquest/venv/bin/gunicorn manquant (deploy/remote_setup.sh)"
|
||||
[[ -f /opt/pyquest/backend/manage.py ]] && ok "code du backend présent" || ko "code du backend absent (make deploy-backend)"
|
||||
[[ -x "${VENV}/bin/gunicorn" ]] && ok "environnement Python et gunicorn installés" || ko "${VENV}/bin/gunicorn manquant (./deploy/server_setup.sh)"
|
||||
[[ -f "${REPO}/backend/manage.py" ]] && ok "dépôt cloné : ${REPO}" || ko "dépôt introuvable (git clone … /opt/PyQuest)"
|
||||
if git -C "${REPO}" rev-parse --short HEAD >/dev/null 2>&1; then info "version du dépôt : $(git -C "${REPO}" rev-parse --short HEAD) ($(git -C "${REPO}" log -1 --format=%cd --date=short))"; fi
|
||||
if [[ -f /etc/pyquest/env ]]; then
|
||||
perms="$(stat -c '%a %U:%G' /etc/pyquest/env)"
|
||||
ok "/etc/pyquest/env présent (${perms})"
|
||||
@@ -63,7 +67,7 @@ if systemctl is-active --quiet pyquest 2>/dev/null; then
|
||||
esac
|
||||
[[ "$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 http://127.0.0.1:8001/api/auth/check/)" == 401 ]] && ok "contrôle d'accès de l'éditeur répond (401 sans session)" || ko "/api/auth/check/ ne répond pas 401"
|
||||
else
|
||||
ko "service pyquest inactif (sudo systemctl enable --now pyquest ; journalctl -u pyquest -n 50)"
|
||||
ko "service pyquest inactif (systemctl enable --now pyquest ; journalctl -u pyquest -n 50)"
|
||||
fi
|
||||
|
||||
echo "Base de données"
|
||||
|
||||
Reference in New Issue
Block a user