secubox-openwrt/package/secubox/secubox-mesh/files/etc/init.d/secuboxd
CyberMind-FR cd6af3edff feat(secubox-mesh): Add OpenWrt mesh daemon with topology management
Port secuboxd from Debian/Go to OpenWrt shell implementation:
- secuboxd daemon with Unix control socket at /var/run/secuboxd/topo.sock
- secuboxctl CLI compatible with Debian version interface
- Mesh libraries: topology, discovery, election, telemetry, control
- Mesh gate election with weighted scoring (uptime, peers, CPU, memory, role)
- mDNS service discovery (_secubox._udp.local) via umdns
- DID integration via mirrornet identity library
- RPCD handler with 11 ubus methods for LuCI integration
- procd init script with respawn and network triggers
- UCI config sections: mesh, node, telemetry, discovery

Fixes subprocess state access for socat handler by saving daemon state to file.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-26 06:27:45 +01:00

78 lines
1.6 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# SecuBox Mesh Daemon init script
# CyberMind — SecuBox — 2026
START=95
STOP=10
USE_PROCD=1
PROG=/usr/sbin/secuboxd
PIDFILE=/var/run/secuboxd/secuboxd.pid
start_service() {
config_load secubox
local enabled
config_get_bool enabled mesh enabled 1
[ "$enabled" -eq 0 ] && {
echo "secuboxd is disabled"
return 0
}
# Create required directories
mkdir -p /var/run/secuboxd
mkdir -p /var/lib/secubox-mesh
mkdir -p /var/log
procd_open_instance secuboxd
procd_set_param command "$PROG" --foreground
procd_set_param respawn 3600 5 5
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param pidfile "$PIDFILE"
# Reload on network changes
procd_set_param netdev br-lan wg0
procd_set_param file /etc/config/secubox
procd_close_instance
}
stop_service() {
# Clean up socket
rm -f /var/run/secuboxd/topo.sock
# Kill any remaining processes
killall -q secuboxd 2>/dev/null
}
reload_service() {
stop
start
}
service_triggers() {
procd_add_reload_trigger "secubox" "network"
}
status() {
local pid
pid=$(cat "$PIDFILE" 2>/dev/null)
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
echo "secuboxd is running (PID: $pid)"
# Show quick status
if [ -S /var/run/secuboxd/topo.sock ]; then
echo "Socket: /var/run/secuboxd/topo.sock (active)"
secuboxctl mesh status 2>/dev/null
fi
return 0
else
echo "secuboxd is not running"
return 1
fi
}