code wiki / _hdl_build / nx_mgmt_publish_bin.nx
nx_mgmt_publish_bin.nx source
↩ module page · 48 lines · 3816 B
1// nx_mgmt_publish_bin.nx -- submit the ecosystem CONTROL-PLANE binary (nx_mgmt_api) to the publisher
2// (policy=outward, operator-approval-gated; NO direct nx_aw_send). Mirrors nx_hub_publish_hostctl: a
3// separate one-shot so re-runs never duplicate rows. The publisher STAGES (verify landed-sha, ledger) on
4// approval; the live atomic-promote + launch remains the operator/hostctl step.
5// - nx_mgmt_api.elf -> /volume1/homes/elderwesto/nishihost/nx_mgmt_api.elf.new (control plane :18098)
6// Launch (operator/hostctl, per the live runbook): ./nx_mgmt_api.elf 18098 <login-daemon keys> <store>
7// 'Nishi Wiki' mgmt_snap.json 1000000000 -- realm/keys/store MUST match the :9091 login daemon that
8// issues the X-Nishi-Session tokens, or every valid session is rejected. Then /health is the live surface.
9// Sovereign: nx_syscalls + nx_publisher. license_tier: ORIGINAL
10import "nx_syscalls.nx"
11import "nx_publisher.nx"
12func pp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func pn(v: i64) -> i64 { var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let bb: *u8=sys_mmap(28); var k: i64=0; if m==0 { bb[0]=48 as u8; sys_write(1,bb,1); return 0 } let t: *u8=sys_mmap(28); while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var i: i64=0; while i<k { bb[i]=t[k-1-i]; i=i+1 } sys_write(1,bb,k); return 0 }
14// self-stage the sovereign build output (/tmp/*.sov.elf) to a DURABLE repo path (_offc) via syscalls
15// (sovereign read+write, NO shell cp), so the publisher's ship-time re-read of src survives a /tmp wipe.
16// Same content -> same sha256 -> idempotent with any prior /tmp-sourced queue row (ledger dedups, rule #10).
17func stage(src: *u8, dst: *u8) -> i64 {
18 let lenp: *i64 = sys_mmap(8) as *i64
19 let data: *u8 = sys_read_file(src, lenp)
20 if (data as i64) == 0 { return 0 - 1 }
21 let fd: i64 = sys_openat_wr(dst, 493)
22 if fd < 0 { return 0 - 2 }
23 sys_write(fd, data, lenp[0])
24 sys_close(fd)
25 return 0
26}
27func main(argc: i64, argv: *i64) -> i64 {
28 pp("=== nx_mgmt_publish_bin: CONTROL-PLANE BUNDLE (API + snapshot monitor) -> publisher queue (outward, operator-approval-gated) ===\n" as *u8)
29 // -- the control-plane API (:18098) --
30 let st1: i64 = stage("/tmp/nx_mgmt_api.sov.elf" as *u8, "_offc/nx_mgmt_api.elf" as *u8)
31 pp(" stage nx_mgmt_api rc=" as *u8); pn(st1); pp("\n" as *u8)
32 let r1: i64 = pub_submit("_offc/nx_mgmt_api.elf" as *u8, "/volume1/homes/elderwesto/nishihost/nx_mgmt_api.elf.new" as *u8, "nishifamily.com" as *u8, "elderwesto" as *u8, "outward" as *u8)
33 pp(" submit nx_mgmt_api.elf (control plane :18098) -> " as *u8)
34 if r1 == 1 { pp("QUEUED\n" as *u8) } else { pp("FAIL r=" as *u8); pn(r1); pp("\n" as *u8) }
35 // -- the snapshot monitor: writes the SUP/SVC snapshot the API reads (so /api/health has real data, not
36 // UNKNOWN). One-shot; schedule it (hostctl/cron) to refresh mgmt_snap.json. --
37 let st2: i64 = stage("/tmp/nx_mgmt_snapshot_run.sov.elf" as *u8, "_offc/nx_mgmt_snapshot_run.elf" as *u8)
38 pp(" stage nx_mgmt_snapshot_run rc=" as *u8); pn(st2); pp("\n" as *u8)
39 let r2: i64 = pub_submit("_offc/nx_mgmt_snapshot_run.elf" as *u8, "/volume1/homes/elderwesto/nishihost/nx_mgmt_snapshot_run.elf.new" as *u8, "nishifamily.com" as *u8, "elderwesto" as *u8, "outward" as *u8)
40 pp(" submit nx_mgmt_snapshot_run.elf (health monitor) -> " as *u8)
41 if r2 == 1 { pp("QUEUED\n" as *u8) } else { pp("FAIL r=" as *u8); pn(r2); pp("\n" as *u8) }
42 var ok: i64 = 0
43 if r1 == 1 { ok = ok + 1 }
44 if r2 == 1 { ok = ok + 1 }
45 pp("RESULT queued=" as *u8); pn(ok); pp("/2 (operator approve+promote; then launch nx_mgmt_api :18098 + schedule the monitor to refresh mgmt_snap.json)\n" as *u8)
46 if ok == 2 { sys_exit(0); return 0 }
47 sys_exit(1); return 1
48}