From 06d8360922b4413996a65842eee550978409a6b5 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Wed, 13 Aug 2025 14:45:56 -0500 Subject: [PATCH] web autostart troubleshooting --- web_interface_v2.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/web_interface_v2.py b/web_interface_v2.py index 8fd24661..6689f888 100644 --- a/web_interface_v2.py +++ b/web_interface_v2.py @@ -1054,13 +1054,20 @@ def run_action_route(): @app.route('/get_logs', methods=['GET']) def get_logs(): try: - # Get logs from journalctl for the ledmatrix service - result = subprocess.run( - ['journalctl', '-u', 'ledmatrix.service', '-n', '500', '--no-pager'], - capture_output=True, text=True, check=False - ) - if result.returncode == 0: - return jsonify({'status': 'success', 'logs': result.stdout}) + # Prefer journalctl logs for ledmatrix; apply a timeout to avoid UI hangs + journal_cmd = ['journalctl', '-u', 'ledmatrix.service', '-n', '500', '--no-pager', '--output=cat'] + try: + result = subprocess.run(journal_cmd, capture_output=True, text=True, check=False, timeout=5) + if result.returncode == 0: + return jsonify({'status': 'success', 'logs': result.stdout}) + # Try sudo fallback (in case group membership hasn't applied yet) + sudo_result = subprocess.run(['sudo', '-n'] + journal_cmd, capture_output=True, text=True, check=False, timeout=5) + if sudo_result.returncode == 0: + return jsonify({'status': 'success', 'logs': sudo_result.stdout}) + error_msg = result.stderr or sudo_result.stderr or 'permission denied' + except subprocess.TimeoutExpired: + error_msg = 'journalctl timed out' + # Permission denied or other error: fall back to web UI log and return hint fallback_logs = '' try: @@ -1068,8 +1075,8 @@ def get_logs(): fallback_logs = f.read() except Exception: fallback_logs = '(No fallback web UI logs found)' - hint = 'Insufficient permissions to read system journal. Add the web user to the systemd-journal group or configure sudoers for journalctl.' - return jsonify({'status': 'error', 'message': f'Error fetching logs: {result.stderr or "permission denied"}\n\nHint: {hint}', 'fallback': fallback_logs}), 500 + hint = 'Insufficient permissions or timeout reading system journal. Ensure the web user is in the systemd-journal group, restart the service to pick up group changes, or configure sudoers for journalctl.' + return jsonify({'status': 'error', 'message': f'Error fetching logs: {error_msg}\n\nHint: {hint}', 'fallback': fallback_logs}), 500 except subprocess.CalledProcessError as e: # If the command fails, return the error error_message = f"Error fetching logs: {e.stderr}"