56 lines
2.2 KiB
JavaScript
56 lines
2.2 KiB
JavaScript
|
|
const { Client } = require('ssh2');
|
||
|
|
const fs = require('fs');
|
||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
const c = new Client();
|
||
|
|
const REMOTE_BASE = '/www/wwwroot/demo.tensorgrove.com.cn/server/services';
|
||
|
|
|
||
|
|
// Read local files
|
||
|
|
const gatewayPath = path.join(__dirname, '..', 'test2', 'server', 'services', 'nativeVoiceGateway.js');
|
||
|
|
const toolExecPath = path.join(__dirname, '..', 'test2', 'server', 'services', 'toolExecutor.js');
|
||
|
|
|
||
|
|
const gatewayContent = fs.readFileSync(gatewayPath, 'utf8');
|
||
|
|
const toolExecContent = fs.readFileSync(toolExecPath, 'utf8');
|
||
|
|
|
||
|
|
console.log(`Gateway file size: ${gatewayContent.length} bytes`);
|
||
|
|
console.log(`ToolExecutor file size: ${toolExecContent.length} bytes`);
|
||
|
|
|
||
|
|
c.on('ready', () => {
|
||
|
|
console.log('SSH connected, starting SFTP...');
|
||
|
|
c.sftp((err, sftp) => {
|
||
|
|
if (err) { console.error('SFTP error:', err); c.end(); return; }
|
||
|
|
|
||
|
|
let done = 0;
|
||
|
|
const total = 2;
|
||
|
|
function checkDone() {
|
||
|
|
done++;
|
||
|
|
if (done >= total) {
|
||
|
|
console.log('All files uploaded. Restarting PM2...');
|
||
|
|
c.exec('cd /www/wwwroot/demo.tensorgrove.com.cn && pm2 restart bigwo-server && sleep 2 && pm2 logs bigwo-server --lines 20 --nostream', (err2, s) => {
|
||
|
|
if (err2) { console.error('Restart error:', err2); c.end(); return; }
|
||
|
|
let o = '';
|
||
|
|
s.on('data', (d) => (o += d));
|
||
|
|
s.stderr.on('data', (d) => (o += d));
|
||
|
|
s.on('close', () => {
|
||
|
|
console.log('=== PM2 Restart Output ===');
|
||
|
|
console.log(o);
|
||
|
|
c.end();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Upload nativeVoiceGateway.js
|
||
|
|
const ws1 = sftp.createWriteStream(`${REMOTE_BASE}/nativeVoiceGateway.js`);
|
||
|
|
ws1.on('close', () => { console.log('✓ nativeVoiceGateway.js uploaded'); checkDone(); });
|
||
|
|
ws1.on('error', (e) => { console.error('Upload gateway error:', e); });
|
||
|
|
ws1.end(gatewayContent);
|
||
|
|
|
||
|
|
// Upload toolExecutor.js
|
||
|
|
const ws2 = sftp.createWriteStream(`${REMOTE_BASE}/toolExecutor.js`);
|
||
|
|
ws2.on('close', () => { console.log('✓ toolExecutor.js uploaded'); checkDone(); });
|
||
|
|
ws2.on('error', (e) => { console.error('Upload toolExec error:', e); });
|
||
|
|
ws2.end(toolExecContent);
|
||
|
|
});
|
||
|
|
}).connect({ host: '119.45.10.34', port: 22, username: 'root', password: '#xyzh%CS#2512@28' });
|