SPB Git forge
29commits 1branches 0releases
684.0 KBsize
maindefault branch
2 days agolast push
Python 95.8% Shell 4.2%

prepare : pm2 startup sous sudo (fin du « à faire manuellement ») + repli LaunchDaemon système quand le domaine gui est absent (nœuds loués sans session graphique)

Simon-Pierre Boucher committed 16 days ago (Sep 8, 2026) parent b96e6dd

1 changed file +13 −2

modified mld/prepare.py +13 −2
@@ -39,8 +39,19 @@ def prepare(alias, runtimes=None, ka_helpers=False):
39 39 script += "[ -f ~/.maclustr-node ] || echo %s > ~/.maclustr-node\n" % alias
40 40 # pm2 startup (launchd) — nécessite sudo
41 41 pw = _sudo_pw(alias)
42 − script += "mkdir -p ~/Library/LaunchAgents; if ! ls ~/Library/LaunchAgents 2>/dev/null | grep -qi pm2; then cmd=$(pm2 startup launchd -u %s --hp %s 2>/dev/null | grep '^sudo' | head -1); if [ -n \"$cmd\" ]; then %s echo \" pm2 startup: $( ${cmd#sudo } >/dev/null 2>&1 && echo ok || echo 'à faire manuellement')\"; fi; fi\n" % (
43 − config.user_of(alias), config.home_of(alias), ("echo %s | sudo -S -v 2>/dev/null;" % shlex.quote(pw)) if pw else "")
42 + # pm2 startup doit tourner sous sudo (écrit le plist + launchctl load) ; l'ancien `${cmd#sudo }` le lançait sans sudo → « à faire manuellement »
43 + if pw:
44 + script += ("mkdir -p ~/Library/LaunchAgents; if ! ls ~/Library/LaunchAgents 2>/dev/null | grep -qi pm2; then "
45 + "if echo %s | sudo -S -p '' env PATH=\"$PATH\" pm2 startup launchd -u %s --hp %s >/dev/null 2>&1; then echo ' pm2 startup: ok'; else echo ' pm2 startup: ÉCHEC'; fi; fi\n"
46 + "launchctl list 2>/dev/null | grep -qi pm2 || launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/pm2.*.plist >/dev/null 2>&1; "
47 + "launchctl list 2>/dev/null | grep -qi pm2 && echo ' pm2 launchd: chargé' || echo ' pm2 launchd: NON chargé'\n"
48 + # nœud sans session graphique (loué, M2U64…) : le domaine gui n'existe pas au boot → LaunchDaemon système avec UserName
49 + "if ! launchctl print gui/$(id -u) >/dev/null 2>&1; then P=$(ls ~/Library/LaunchAgents/pm2.*.plist 2>/dev/null | head -1); "
50 + "if [ -n \"$P\" ]; then L=$(/usr/libexec/PlistBuddy -c 'Print :Label' \"$P\"); D=/Library/LaunchDaemons/$(basename \"$P\"); "
51 + "echo %s | sudo -S -p '' sh -c \"cp '$P' '$D' && /usr/libexec/PlistBuddy -c 'Delete :UserName' '$D' 2>/dev/null; /usr/libexec/PlistBuddy -c 'Add :UserName string %s' '$D' && chown root:wheel '$D' && chmod 644 '$D' && launchctl bootout system/$L 2>/dev/null; launchctl bootstrap system '$D' 2>/dev/null; launchctl print system/$L >/dev/null 2>&1 && echo ' pm2 LaunchDaemon (pas de session graphique) : chargé' || echo ' pm2 LaunchDaemon : NON chargé'\"; fi; fi\n") % (
52 + shlex.quote(pw), config.user_of(alias), config.home_of(alias), shlex.quote(pw), config.user_of(alias))
53 + else:
54 + script += "echo ' pm2 startup: mot de passe sudo absent (%s)'\n" % config.sudo_pw_file(alias)
44 55 rc, out, err = ssh.run(ip, script, timeout=1800)
45 56 if ka_helpers:
46 57 out += ka_helpers_install(alias, ip)
47 58