const { Client } = require('ssh2'); const conn = new Client(); conn.on('ready', () => { console.log('=== 重启Docker容器 ==='); conn.exec('cd /www/huishou && docker-compose down && docker-compose up -d', (err2, stream2) => { if (err2) { console.log('ERR2:', err2); conn.end(); return; } stream2.on('data', (d) => process.stdout.write(d.toString())); stream2.on('close', () => { setTimeout(() => { console.log('\n=== 测试网站 ==='); conn.exec('curl -s http://127.0.0.1:4001/ | head -3', (err3, stream3) => { if (err3) { console.log('ERR3:', err3); conn.end(); return; } stream3.on('data', (d) => console.log(d.toString())); stream3.on('close', () => { console.log('\n✅ 重启完成!'); conn.end(); }); }); }, 15000); }); }); }); conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' });