SPB Git

Repository Public

add-worker.sh 4.3 KB 59 lines shellscript

1#!/bin/zsh2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : MacLustr Identity8# File             : scripts/add-worker.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# Ajoute un worker d'inférence sur un autre Mac du MacLustr (à lancer du laptop ou d'un poste opérateur).42#   usage : scripts/add-worker.sh <nœud-hôte> <nœud-worker>      ex. scripts/add-worker.sh M2M32c M4M64c43# Le worker n'écoute sur aucun port : il appelle l'API interne de l'hôte (réseau local, port 8862) en TLS mutuel, avec son jeton.44set -euo pipefail45HOST="$1"; W="$2"46ENVV='export PATH=/opt/homebrew/bin:$HOME/.local/bin:$PATH DATABASE_URL=postgres://127.0.0.1/maclustr_identity MLID_ENV=production MLID_MASTER_KEY_FILE=$HOME/.config/maclustr-identity/master.key'47HOST_IP=$(ssh "$HOST" "ipconfig getifaddr en0 || ipconfig getifaddr en1")48TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT49ssh "$HOST" "$ENVV; cd ~/apps/maclustr-identity && .venv/bin/python -m services.mlid.cli pki-init >/dev/null && .venv/bin/python -m services.mlid.cli pki-issue-worker $W >/dev/null && .venv/bin/python -m services.mlid.cli worker-register $W" > "$TMP/worker.token"50scp -q "${HOST}:.config/maclustr-identity/pki/ca.pem" "${HOST}:.config/maclustr-identity/pki/worker-$W.pem" "${HOST}:.config/maclustr-identity/pki/worker-$W.key" "$TMP/"51ssh "$HOST" "rm -f ~/.config/maclustr-identity/pki/worker-$W.key"52ssh "$W" 'mkdir -p ~/apps/maclustr-identity-worker ~/.config/maclustr-identity-worker && chmod 700 ~/.config/maclustr-identity-worker'53cd "$(dirname "$0")/.."54rsync -a --delete --exclude '__pycache__' --exclude '.venv' services models requirements.lock scripts "${W}:apps/maclustr-identity-worker/"55ssh "$W" 'test -f ~/apps/maclustr-identity-worker/services/mlid/worker/main.py' || { echo "copie du code en échec"; exit 1; }56scp -q "$TMP/worker.token" "$TMP/ca.pem" "$TMP/worker-$W.pem" "$TMP/worker-$W.key" "${W}:.config/maclustr-identity-worker/"57ssh "$W" "export PATH=/opt/homebrew/bin:\$HOME/.local/bin:\$PATH; chmod 600 ~/.config/maclustr-identity-worker/*; cd ~/apps/maclustr-identity-worker && { [ -x .venv/bin/python ] || uv venv --python 3.12 .venv -q; } && uv pip install -q --python .venv/bin/python -r requirements.lock && zsh scripts/fetch-models.sh && C=\$HOME/.config/maclustr-identity-worker && pm2 delete maclustr-identity-worker >/dev/null 2>&1; MLID_ENV=production MLID_WORKER_PROCS=${MLID_WORKER_PROCS:-3} MLID_INTERNAL_RELAY=1 MLID_INTERNAL_URL=https://$HOST_IP:8862 MLID_WORKER_TOKEN_FILE=\$C/worker.token MLID_INTERNAL_CA=\$C/ca.pem MLID_WORKER_CERT=\$C/worker-$W.pem MLID_WORKER_KEY=\$C/worker-$W.key MLID_MASTER_KEY_FILE=/dev/null pm2 start .venv/bin/python --name maclustr-identity-worker --interpreter none --max-memory-restart 3G --kill-timeout 15000 -- -m services.mlid.worker.main >/dev/null && pm2 save >/dev/null && sleep 6 && pm2 logs maclustr-identity-worker --lines 3 --nostream 2>&1 | tail -2"58echo "worker $W → $HOST ($HOST_IP:8862)"59
Files main
Menu

Theme