31 lines
1.3 KiB
JavaScript
31 lines
1.3 KiB
JavaScript
|
|
const { Client } = require('ssh2');
|
||
|
|
const fs = require('fs');
|
||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
const c = new Client();
|
||
|
|
const localFile = path.join(__dirname, '..', 'test2', 'server', 'services', 'nativeVoiceGateway.js');
|
||
|
|
const remotePath = '/www/wwwroot/demo.tensorgrove.com.cn/server/services/nativeVoiceGateway.js';
|
||
|
|
|
||
|
|
const content = fs.readFileSync(localFile, 'utf8');
|
||
|
|
|
||
|
|
c.on('ready', () => {
|
||
|
|
console.log('SSH connected, deploying nativeVoiceGateway.js...');
|
||
|
|
c.sftp((err, sftp) => {
|
||
|
|
if (err) { console.error('SFTP error:', err.message); c.end(); return; }
|
||
|
|
const ws = sftp.createWriteStream(remotePath);
|
||
|
|
ws.on('close', () => {
|
||
|
|
console.log('File uploaded successfully.');
|
||
|
|
c.exec('pm2 restart bigwo-server && sleep 2 && pm2 logs bigwo-server --nostream --lines 5', (err, s) => {
|
||
|
|
if (err) { console.error('Restart error:', err.message); 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:\n' + o); c.end(); });
|
||
|
|
});
|
||
|
|
});
|
||
|
|
ws.on('error', (err) => { console.error('Write error:', err.message); c.end(); });
|
||
|
|
ws.write(content);
|
||
|
|
ws.end();
|
||
|
|
});
|
||
|
|
}).connect({ host: '119.45.10.34', port: 22, username: 'root', password: '#xyzh%CS#2512@28' });
|