51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
import { Client } from "ssh2";
|
||
|
||
const SSH_CONFIG = {
|
||
host: "119.45.10.34",
|
||
port: 22,
|
||
username: "root",
|
||
password: "#xyzh%CS#2512@28",
|
||
readyTimeout: 10000,
|
||
};
|
||
|
||
function sshExec(command) {
|
||
return new Promise((resolve, reject) => {
|
||
const conn = new Client();
|
||
let stdout = "";
|
||
let stderr = "";
|
||
conn.on("ready", () => {
|
||
conn.exec(command, (err, stream) => {
|
||
if (err) { conn.end(); return reject(err); }
|
||
stream.on("close", (code) => { conn.end(); resolve({ stdout, stderr, code }); });
|
||
stream.on("data", (d) => { stdout += d.toString(); });
|
||
stream.stderr.on("data", (d) => { stderr += d.toString(); });
|
||
});
|
||
}).on("error", (err) => reject(err)).connect(SSH_CONFIG);
|
||
});
|
||
}
|
||
|
||
async function main() {
|
||
console.log("=== 检查 PM2 状态 ===");
|
||
const pm2Status = await sshExec("pm2 list");
|
||
console.log(pm2Status.stdout);
|
||
|
||
console.log("\n=== 检查语法(在服务器上直接运行 node --check) ===");
|
||
const checkSyntax = await sshExec("cd /www/wwwroot/demo.tensorgrove.com.cn && node --check server/routes/voice.js 2>&1 || echo 'Check complete'");
|
||
console.log(checkSyntax.stdout);
|
||
console.log(checkSyntax.stderr);
|
||
|
||
console.log("\n=== 健康检查 ===");
|
||
const health = await sshExec("curl -s http://127.0.0.1:3012/api/health 2>&1");
|
||
console.log("Health Check:", health.stdout);
|
||
|
||
console.log("\n=== 最近一次通话的服务器日志 ===");
|
||
const logs = await sshExec("pm2 logs bigwo-server --nostream --lines 100");
|
||
console.log(logs.stdout);
|
||
|
||
console.log("\n=== 错误日志 ===");
|
||
const errorLogs = await sshExec("tail -n 100 /var/log/bigwo/server-error.log");
|
||
console.log(errorLogs.stdout);
|
||
}
|
||
|
||
main().catch(e => { console.error("Fatal:", e.message); process.exit(1); });
|