46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 验证配置文件 ===\n');
|
|
|
|
conn.exec('cat /www/server/panel/vhost/nginx/hs.yifenbao.cn.conf', (err, stream) => {
|
|
if (err) {
|
|
console.log('读取配置失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream.on('data', (data) => {
|
|
console.log('当前配置:', data.toString());
|
|
});
|
|
|
|
stream.on('close', () => {
|
|
conn.exec('/www/server/nginx/sbin/nginx -t', (err, stream2) => {
|
|
if (err) {
|
|
console.log('配置检查失败:', err.message);
|
|
} else {
|
|
stream2.on('data', (data2) => {
|
|
console.log('\n配置检查:', data2.toString());
|
|
});
|
|
}
|
|
|
|
stream2.on('close', () => {
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |