Keep OPNsense telemetry when the script worker cannot start and build it for FreeBSD 14.1
A worker linked on the FreeBSD 15 test guest needs FBSD_1.9 and does not load on OPNsense 24.7; the agent then retried the job session every 30 s and never sent a heartbeat or inventory. The agent now pauses script capabilities for an hour and reconnects without them. tools/dev_opnsense_worker.py links the worker against the official FreeBSD 14.1 pkgbase libraries. The installer checks that the worker loads before binding it and reports success only after a heartbeat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,11 @@ mod root;
|
||||
fn main() -> anyhow::Result<()> {
|
||||
match std::env::args().nth(1).as_deref() {
|
||||
Some("--root-helper") => root::serve(),
|
||||
// Loader check for installers: resolves every symbol against this system's libc.
|
||||
Some("--version") => {
|
||||
println!("{}", env!("CARGO_PKG_VERSION"));
|
||||
Ok(())
|
||||
}
|
||||
Some("--root-capabilities") => {
|
||||
println!("{}", serde_json::to_string(&root::caps()?)?);
|
||||
Ok(())
|
||||
|
||||
@@ -138,6 +138,16 @@ def bind_jobs(meta, host, port):
|
||||
os.fsync(f.fileno())
|
||||
|
||||
|
||||
def worker_starts():
|
||||
"""The native worker must load on this FreeBSD release; resolve all symbols now."""
|
||||
try:
|
||||
res = subprocess.run([str(APP / 'rmm-opnsense-jobs'), '--version'], capture_output=True, timeout=15,
|
||||
env={**os.environ, 'LD_BIND_NOW': '1'})
|
||||
except OSError:
|
||||
return False
|
||||
return res.returncode == 0
|
||||
|
||||
|
||||
def running():
|
||||
return all(Path(f'/var/run/discovery-{part}.pid').is_file() for part in ('agent', 'collect'))
|
||||
|
||||
@@ -175,24 +185,32 @@ def main():
|
||||
if res.returncode:
|
||||
stop('Die Aufnahme beim Server ist fehlgeschlagen. Bitte einen neuen Einmalcode erzeugen.')
|
||||
print('Gerät beim Server aufgenommen.')
|
||||
if (APP / 'rmm-opnsense-jobs').is_file() and not BINDING.exists():
|
||||
worker = (APP / 'rmm-opnsense-jobs').is_file()
|
||||
if worker and not worker_starts():
|
||||
worker = False
|
||||
print('Hinweis: Der Skript-Worker startet auf dieser OPNsense-Version nicht. '
|
||||
'Inventur und Heartbeat laufen, Skripte sind bis zu einem passenden Paket nicht verfügbar.')
|
||||
if worker and not BINDING.exists():
|
||||
bind_jobs(meta, host, port)
|
||||
print('Skriptausführung für diese Installation gebunden.')
|
||||
before = device_view(host, port) if existing else None
|
||||
before = device_view(host, port)
|
||||
generation = int(before['installed']['connection_generation']) if before else -1
|
||||
contact = before['installed'].get('last_contact_at') if before else None
|
||||
subprocess.run(['service', 'discovery_agent', 'restart' if running() else 'start'], check=True,
|
||||
stdout=subprocess.DEVNULL)
|
||||
for _ in range(30):
|
||||
time.sleep(3)
|
||||
view = running() and device_view(host, port)
|
||||
# A new client hello raises the connection generation and reports the installed version.
|
||||
# A new client hello raises the connection generation and reports the installed version;
|
||||
# only a heartbeat after it (new last contact) shows that telemetry actually flows.
|
||||
if (view and view['installed'].get('agent_version') == meta['version']
|
||||
and int(view['installed']['connection_generation']) > generation):
|
||||
and int(view['installed']['connection_generation']) > generation
|
||||
and view['installed'].get('last_contact_at') not in (None, contact)):
|
||||
print(f'Fertig. Das Gerät meldet sich mit Version {view["installed"]["agent_version"]} '
|
||||
'und erscheint in der WebUI unter Geräte.')
|
||||
return
|
||||
stop('Der Dienst läuft, hat sich aber noch nicht beim Server gemeldet. '
|
||||
'Diagnose: /var/log/system/latest.log und service discovery_agent restart.')
|
||||
stop('Der Dienst läuft, sendet aber keinen Heartbeat. '
|
||||
'Diagnose: grep discovery-agent /var/log/system/latest.log | tail')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user