MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_logs

Function get_logs

webapp_modern.py:6932–7033  ·  view source on GitHub ↗

Get recent logs - prioritizing orchestrator.py output

()

Source from the content-addressed store, hash-verified

6930 cmd = ['bash', script_path] if os.geteuid() == 0 else ['sudo', '-n', 'bash', script_path]
6931 if arg:
6932 cmd.append(arg)
6933 try:
6934 with open(SENSING_INSTALL_LOG, 'a') as logf:
6935 logf.write(f"\n=== run {os.path.basename(script_path)} {arg or ''} ===\n")
6936 logf.flush()
6937 subprocess.run(cmd, stdout=logf, stderr=subprocess.STDOUT,
6938 env={**os.environ, 'SENSING_INSTALL_LOG': SENSING_INSTALL_LOG},
6939 timeout=3600)
6940 except Exception as exc:
6941 logger.error(f"sensing script {script_path} failed: {exc}")
6942 finally:
6943 with _sensing_install_lock:
6944 _sensing_installing = False
6945
6946
6947@app.route('/api/sensing/status', methods=['GET'])
6948def sensing_status():
6949 """Report whether the bundled sensing backend is installed and running."""
6950 installed, active = _sensing_unit_state()
6951 arch = os.uname().machine
6952 has_prebuilt = (arch == 'aarch64' and
6953 os.path.exists(os.path.join(shared_data.currentdir, 'bin', 'sensing-server')))
6954 with _sensing_install_lock:
6955 installing = _sensing_installing
6956 return jsonify({
6957 'success': True, 'installed': installed, 'active': active,
6958 'installing': installing, 'arch': arch, 'has_prebuilt': has_prebuilt,
6959 })
6960
6961
6962@app.route('/api/sensing/install', methods=['POST'])
6963def sensing_install():
6964 """Install (or rebuild) the bundled sensing backend in the background."""
6965 global _sensing_installing
6966 with _sensing_install_lock:
6967 if _sensing_installing:
6968 return jsonify({'success': True, 'message': 'Install already in progress', 'installing': True})
6969 _sensing_installing = True
6970 rebuild = bool((request.get_json(silent=True) or {}).get('rebuild'))
6971 open(SENSING_INSTALL_LOG, 'w').close() # fresh log per run
6972 threading.Thread(target=_run_sensing_script,
6973 args=(SENSING_INSTALL_SCRIPT, '--rebuild' if rebuild else None),
6974 daemon=True, name='sensing-install').start()
6975 return jsonify({'success': True, 'message': 'Sensing backend install started', 'installing': True})
6976
6977
6978@app.route('/api/sensing/uninstall', methods=['POST'])
6979def sensing_uninstall():
6980 """Stop and remove the bundled sensing backend."""
6981 threading.Thread(target=_run_sensing_script, args=(SENSING_UNINSTALL_SCRIPT,),
6982 daemon=True, name='sensing-uninstall').start()
6983 return jsonify({'success': True, 'message': 'Sensing backend uninstall started'})
6984
6985
6986@app.route('/api/sensing/restart', methods=['POST'])
6987def sensing_restart():
6988 """Restart the bundled sensing service (systemctl restart) without a full reinstall.
6989

Callers 1

legacy_logsFunction · 0.85

Calls 4

extendMethod · 0.80
sortMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected