#!/bin/sh # Frequent service-invite sync — run by the Cloudron scheduler addon every # few minutes. # # WHY: a new member is provisioned with an UNACTIVATED Cloudron account, and # the Loomio/Matrix syncs deliberately skip an unactivated account (never # invite a half-created one). The member activates later, by following the # setup link in their welcome email — and until this job existed, the next # thing to look at them was the 3x/day membership sweep, so a brand-new member # could sit without forum or Space access for hours. # # Calls the portal's own /admin/service-sync endpoint (localhost), which fires # the same idempotent Loomio + Matrix syncs the sweep runs, but ONLY while some # member is still awaiting their invites (one SELECT when nobody is). # # The ADMIN_TOKEN env var is shared with the main app (the scheduler runs in # the same launch environment), so we use it to authenticate. Admin auth is a # header, never a URL token. # # Deliberately NOT the full /admin/sweep: that reconciles against Open # Collective, runs allowance logic and can send member mail. This job must only # ever send the invites a member is owed. set -e if [ -z "$ADMIN_TOKEN" ]; then echo "service-sync: ADMIN_TOKEN is not set; aborting" >&2 exit 1 fi python3 - "$ADMIN_TOKEN" <<'PY' import sys, urllib.request, urllib.error token = sys.argv[1] url = "http://127.0.0.1:8000/admin/service-sync" req = urllib.request.Request(url, method="POST", data=b"", headers={ "Content-Type": "application/json", "X-Admin-Token": token, }) try: with urllib.request.urlopen(req, timeout=300) as resp: print("service-sync:", resp.read().decode()) except urllib.error.HTTPError as e: print(f"service-sync: HTTP {e.code}: {e.read().decode()}", file=sys.stderr) sys.exit(1) except Exception as e: print(f"service-sync: request failed: {e}", file=sys.stderr) sys.exit(1) PY