You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.9 KiB
41 lines
1.9 KiB
|
1 week ago
|
# -*- coding: utf-8 -*-
|
||
|
|
"""票 04:带超时的一次性诊断(健康探测 + 启动日志 + 端口/进程状态)。"""
|
||
|
|
import io, sys, subprocess
|
||
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||
|
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
|
||
|
|
|
||
|
|
# 1) 8080 健康探测(5s 超时)
|
||
|
|
try:
|
||
|
|
import requests
|
||
|
|
r = requests.get('http://localhost:8080/api/auth/debug/token',
|
||
|
|
params={'userId': '739564171091247104'}, timeout=5)
|
||
|
|
print(f"[health] HTTP {r.status_code} {r.text[:150]}")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"[health] FAIL: {type(e).__name__}: {e}")
|
||
|
|
|
||
|
|
# 2) 启动日志尾部
|
||
|
|
try:
|
||
|
|
txt = open(r'e:\code\crm-backend-matt\logs\t04-run.log', encoding='utf-8', errors='replace').read()
|
||
|
|
print(f"[log] size={len(txt)}")
|
||
|
|
if 'Started CrmApplication' in txt:
|
||
|
|
i = txt.find('Started CrmApplication')
|
||
|
|
print('[log] ' + txt[i:i + 120].splitlines()[0])
|
||
|
|
if 'APPLICATION FAILED' in txt:
|
||
|
|
i = txt.find('APPLICATION FAILED')
|
||
|
|
print('[log-FAIL] ' + txt[i:i + 800])
|
||
|
|
lines = [l for l in txt.splitlines() if l.strip()]
|
||
|
|
print('[log-tail] ' + ' | '.join(lines[-3:]))
|
||
|
|
except FileNotFoundError:
|
||
|
|
print('[log] t04-run.log 不存在(start.cmd 未成功执行或日志路径未生成)')
|
||
|
|
|
||
|
|
# 3) 端口监听(subprocess 带 timeout=10)
|
||
|
|
r = subprocess.run(['netstat', '-ano'], capture_output=True, text=True, timeout=10)
|
||
|
|
listeners = [l.strip() for l in r.stdout.splitlines()
|
||
|
|
if ('LISTENING' in l) and (' 8080 ' in l or ' 8081 ' in l or ':8080' in l or ':8081' in l)]
|
||
|
|
print('[netstat]', listeners if listeners else '8080/8081 无监听')
|
||
|
|
|
||
|
|
# 4) java 进程(subprocess 带 timeout=10)
|
||
|
|
r = subprocess.run(['tasklist'], capture_output=True, text=True, timeout=10)
|
||
|
|
javas = [l.strip() for l in r.stdout.splitlines() if l.lower().startswith('java')]
|
||
|
|
print('[tasklist]', javas if javas else '无 java 进程')
|