Repository Public
1#!/bin/zsh2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : MacLustr Identity8# File : scripts/staging.sh9# Module : scripts10# Repository : https://git.spboucher.ai/maclustr-identity11# Project Website : https://identity.spboucher.ai12# Created : 2026-12-0113# Last Modified : 2026-12-0114#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# Préproduction sur le nœud : instance séparée (base, clé, données, ports) du même code, pour des essais consentis avec de vraies pièces.42# usage : scripts/staging.sh start|stop|status|cli <commande…>43# N'est PAS la production : base maclustr_identity_staging, clé ~/.config/maclustr-identity-staging/master.key, ports 8870/8871.44set -euo pipefail45export PATH="/opt/homebrew/bin:/opt/homebrew/opt/postgresql@17/bin:$HOME/.local/bin:$PATH"46cd "$(dirname "$0")/.."47CONF="$HOME/.config/maclustr-identity-staging"; DATA="$HOME/maclustr-identity-staging-data"48ORIGIN="${MLID_STAGING_ORIGIN:-https://identity-staging.51-161-112-61.sslip.io}"49export MLID_ENV=staging DATABASE_URL=postgres://127.0.0.1/maclustr_identity_staging MLID_MASTER_KEY_FILE="$CONF/master.key" MLID_DATA_DIR="$DATA" \50 MLID_ORIGIN="$ORIGIN" MLID_RP_ID="${ORIGIN#https://}" MLID_TRUST_PROXY="10.67.0.1,127.0.0.1" MLID_ALLOWED_PEERS="127.0.0.1,10.67.0.1" MLID_DB_POOL_MAX=3 MLID_INTERNAL_URL=http://127.0.0.1:8871 MLID_WORKER_TOKEN_FILE="$CONF/worker.token"51NAMES=(mlid-staging mlid-staging-internal mlid-staging-dispatcher mlid-staging-worker)52case "${1:-status}" in53 start)54 mkdir -p "$CONF" "$DATA"; chmod 700 "$CONF" "$DATA"55 psql -d postgres -tAc "select 1 from pg_database where datname='maclustr_identity_staging'" | grep -q 1 || createdb maclustr_identity_staging56 [ -f "$CONF/master.key" ] || (umask 077; head -c 32 /dev/urandom > "$CONF/master.key")57 .venv/bin/python -m services.mlid.cli migrate >/dev/null58 [ -f "$CONF/worker.token" ] || (umask 077; .venv/bin/python -m services.mlid.cli worker-register "staging-$(hostname -s)" > "$CONF/worker.token")59 for n in $NAMES; do pm2 delete $n >/dev/null 2>&1 || true; done60 pm2 start .venv/bin/python --name mlid-staging --interpreter none -- -m uvicorn services.mlid.app:app --host 0.0.0.0 --port 8870 --no-server-header >/dev/null61 pm2 start .venv/bin/python --name mlid-staging-internal --interpreter none -- -m uvicorn services.mlid.internal_app:app --host 127.0.0.1 --port 8871 --no-server-header >/dev/null62 pm2 start .venv/bin/python --name mlid-staging-dispatcher --interpreter none -- -m services.mlid.dispatcher >/dev/null63 pm2 start .venv/bin/python --name mlid-staging-worker --interpreter none -- -m services.mlid.worker.main >/dev/null64 pm2 save >/dev/null; sleep 5; curl -fsS -m 10 http://127.0.0.1:8870/health/ready; echo ;;65 stop) for n in $NAMES; do pm2 delete $n >/dev/null 2>&1 || true; done; pm2 save >/dev/null; echo "préproduction arrêtée" ;;66 cli) shift; .venv/bin/python -m services.mlid.cli "$@" ;;67 *) curl -fsS -m 10 http://127.0.0.1:8870/health/ready || echo "préproduction arrêtée"; echo ;;68esac69