code wiki / _hdl_build / nx_hostop_ctl_gate.nx

nx_hostop_ctl_gate.nx source

↩ module page · 36 lines · 2645 B

1// nx_hostop_ctl_gate.nx -- R11 PROOF: control-plane composition -- pre-apply health decision + supervise command. 2// The host-operator builds the nx_aw_hostctl invocation + decides health from its output (fail-closed); hosting runs it. 3// File-based. license_tier: ORIGINAL expect_exit: 0 4import "nx_syscalls.nx" 5import "nx_hostop.nx" 6 7func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 8func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 9func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 } 10func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 11 12func main() -> i64 { 13 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0 14 g_w("=== NX-HOSTOP-CTL GATE (pre-apply health decision + supervise command; hosting executes) ===\n" as *u8) 15 16 let cmd: *u8 = sys_mmap(256); let cl: i64 = hostop_prehealth_cmd(cmd) 17 let cmd_ok: i64 = pub_substr(cmd, cl, "nx_aw_hostctl status" as *u8) 18 19 // health DECISION over status outputs (the host-operator's gate before touching live) 20 let healthy: *u8 = "host HEALTHY: all 6 services UP" as *u8 21 let down: *u8 = "host: nx_wiki_gw.elf DOWN" as *u8 22 let h_ok: i64 = hostop_prehealth_ok(healthy, slen(healthy)) 23 let h_bad: i64 = hostop_prehealth_ok(down, slen(down)) 24 25 let sup: *u8 = sys_mmap(256); let sl: i64 = hostop_supervise_cmd("startsite" as *u8, "nx_wiki_gw.elf" as *u8, sup) 26 let sup_ok: i64 = (pub_substr(sup, sl, "nx_aw_hostctl startsite" as *u8)) & (pub_substr(sup, sl, "nx_wiki_gw.elf" as *u8)) 27 28 g_w(" prehealth_cmd='" as *u8); g_w(cmd); g_w("' healthy=" as *u8); g_n(h_ok); g_w(" down=" as *u8); g_n(h_bad); g_w("\n supervise_cmd='" as *u8); g_w(sup); g_w("'\n" as *u8) 29 g_row("PRE-HEALTH builds the status command + decides HEALTHY only when services UP" as *u8, ((cmd_ok==1) as i64) & ((h_ok==1) as i64), pass) 30 g_row("FAIL-CLOSED: a DOWN service -> NOT healthy (do not apply)" as *u8, (h_bad==0) as i64, pass) 31 g_row("SUPERVISE builds the control-plane command (startsite <daemon>) for hosting to execute" as *u8, sup_ok, pass) 32 33 g_w("NX-HOSTOP-CTL rows=3 pass=" as *u8); g_n(pass[0]) 34 if pass[0]==3 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 35 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1 36}