code wiki / _hdl_build / nx_keeper.nx

nx_keeper.nx source

↩ module page · 67 lines · 3137 B

1// nx_keeper.nx -- ★ RETIRED / DO NOT RUN (2026-06-16, closes hosting_research gap #9 "single-supervisor"). 2// SUPERSEDED BY nx_hostctl.cmd_supervise, which is the ONE boot supervisor (started by rc.d nishi_sites.sh) 3// and already covers vroom(:8446) + translate(:8447) -- now with PID-liveness + SERVING health-probe 4// (HUNG-aware) + a crash-loop guard, which this keeper lacked. Running BOTH = two supervisors fighting over 5// the same daemons (double-spawn / restart races) = the exact fragmentation gap #9 names. Kept only as 6// history; do not start it and do not add it to rc.d. If found running on the NAS, kill it (nx_hostctl owns 7// supervision). Original purpose preserved below for the record. 8// 9// SOVEREIGN process supervisor for the nishifamily.com/video stack. Durability: the video daemon (:8446) and 10// translate daemon (:8447) were setsid-only -> a crash left them down. Connect-probes both ports every 5s and 11// re-spawns any that's down via fork+execve (reaping zombies via wait4/WNOHANG). Pure nx_syscalls. 12// license_tier: ORIGINAL 13import "nx_syscalls.nx" 14import "nx_connect.nx" // bounded connect: a raw sys_connect hangs ~127s on a black-holed host 15const KP_MAGIC_8446: i64 = 8446 16const KP_MAGIC_8447: i64 = 8447 17const KP_MAGIC_5000: i64 = 5000 18 19const KP_VROOM: *u8 = "/volume1/homes/elderwesto/nishihost/nx_vroom_daemon.elf" as *u8 20const KP_XLATE: *u8 = "/volume1/homes/elderwesto/nishihost/nx_translate_daemon.elf" as *u8 21 22// fill a sockaddr_in (16 bytes) for 127.0.0.1:port (port in network/big-endian order). 23func kp_fill_addr(a: *u8, port: i64) -> i64 { 24 a[0] = 2 as u8; a[1] = 0 as u8 // AF_INET 25 a[2] = ((port >> 8) & 255) as u8; a[3] = (port & 255) as u8 // port, network order 26 a[4] = 127 as u8; a[5] = 0 as u8; a[6] = 0 as u8; a[7] = 1 as u8 // 127.0.0.1 27 return 0 28} 29 30// 1 if something is accepting on 127.0.0.1:port, else 0. (socket-create failure -> assume up, 31// so a transient resource hiccup never triggers a spurious restart.) 32func kp_up(port: i64) -> i64 { 33 let fd: i64 = sys_socket(2, 1, 0) 34 if fd < 0 { return 1 } 35 let a: *u8 = sys_mmap(16) 36 kp_fill_addr(a, port) 37 let rc: i64 = nx_connect_bounded(fd, a, 16, NX_CONN_DEFAULT_MS) 38 sys_close(fd) 39 if rc == 0 { return 1 } 40 return 0 41} 42 43// fork + execve to (re)start a daemon; parent returns the child pid immediately. 44func kp_start(path: *u8) -> i64 { 45 let pid: i64 = sys_fork() 46 if pid == 0 { 47 let argv: *i64 = (sys_mmap(16)) as *i64 48 argv[0] = path as i64 49 argv[1] = 0 50 sys_execve(path, argv, 0 as *i64) 51 sys_exit(127) // only if execve failed 52 } 53 return pid 54} 55 56func main() -> i64 { 57 let status: *i64 = (sys_mmap(8)) as *i64 58 var run: i64 = 1 59 while run == 1 { 60 if kp_up(KP_MAGIC_8446) == 0 { kp_start(KP_VROOM) } 61 if kp_up(KP_MAGIC_8447) == 0 { kp_start(KP_XLATE) } 62 var reaped: i64 = 1 63 while reaped > 0 { reaped = sys_wait4(0 - 1, status, 1) } // WNOHANG: reap dead children 64 sys_sleep_ms(KP_MAGIC_5000) 65 } 66 return 0 67}