63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""检查部署状态"""
|
|
|
|
import paramiko
|
|
import sys
|
|
|
|
SSH_CONFIG = {
|
|
'hostname': '43.139.27.93',
|
|
'port': 22022,
|
|
'username': 'root',
|
|
'password': 'Zhiqun1984'
|
|
}
|
|
|
|
def run_command(ssh, cmd, description):
|
|
"""执行SSH命令"""
|
|
print(f"\n[CMD] {description}")
|
|
print(f" > {cmd}")
|
|
stdin, stdout, stderr = ssh.exec_command(cmd)
|
|
output = stdout.read().decode('utf-8', errors='ignore')
|
|
error = stderr.read().decode('utf-8', errors='ignore')
|
|
|
|
if output:
|
|
print(output)
|
|
if error and 'warning' not in error.lower():
|
|
print(f"[ERROR] {error}")
|
|
|
|
return output
|
|
|
|
def main():
|
|
print("="*60)
|
|
print("Deployment Status Check")
|
|
print("="*60)
|
|
|
|
try:
|
|
# SSH连接
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect(**SSH_CONFIG)
|
|
print("[OK] SSH connected")
|
|
|
|
# 1. 检查PM2状态
|
|
run_command(ssh, 'pm2 status', '1. PM2 process status')
|
|
|
|
# 2. 检查最新日志
|
|
run_command(ssh, 'pm2 logs soul --lines 20 --nostream', '2. Recent PM2 logs')
|
|
|
|
# 3. 检查端口监听
|
|
run_command(ssh, 'netstat -tuln | grep 30006', '3. Port 30006 listening status')
|
|
|
|
# 4. 验证API是否正常
|
|
run_command(ssh, 'curl -s http://localhost:30006/api/config | head -c 200', '4. API health check')
|
|
|
|
ssh.close()
|
|
print("\n[OK] Check completed")
|
|
|
|
except Exception as e:
|
|
print(f"[ERROR] {e}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|