| 160 | |
| 161 | |
| 162 | def serve_logs(self, handler): |
| 163 | try: |
| 164 | log_file_path = self.shared_data.webconsolelog |
| 165 | if not os.path.exists(log_file_path): |
| 166 | subprocess.Popen(f"sudo tail -f /home/ragnar/Ragnar/data/logs/* > {log_file_path}", shell=True) |
| 167 | |
| 168 | with open(log_file_path, 'r') as log_file: |
| 169 | log_lines = log_file.readlines() |
| 170 | |
| 171 | max_lines = 2000 |
| 172 | if len(log_lines) > max_lines: |
| 173 | log_lines = log_lines[-max_lines:] |
| 174 | with open(log_file_path, 'w') as log_file: |
| 175 | log_file.writelines(log_lines) |
| 176 | |
| 177 | log_data = ''.join(log_lines) |
| 178 | |
| 179 | handler.send_response(200) |
| 180 | handler.send_header("Content-type", "text/plain") |
| 181 | handler.end_headers() |
| 182 | handler.wfile.write(log_data.encode('utf-8')) |
| 183 | except BrokenPipeError: |
| 184 | # Ignore broken pipe errors |
| 185 | pass |
| 186 | except Exception as e: |
| 187 | handler.send_response(500) |
| 188 | handler.send_header("Content-type", "application/json") |
| 189 | handler.end_headers() |
| 190 | handler.wfile.write(json.dumps({"status": "error", "message": str(e)}).encode('utf-8')) |
| 191 | |
| 192 | def start_orchestrator(self, handler): |
| 193 | try: |