62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 检查Nginx状态 ===\n');
|
|
|
|
conn.exec('/www/server/nginx/sbin/nginx -t', (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 -s reload', (err, stream2) => {
|
|
if (err) {
|
|
console.log('重启失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream2.on('close', () => {
|
|
console.log('Nginx已重启');
|
|
|
|
setTimeout(() => {
|
|
conn.exec('curl -s -k https://hs.yifenbao.cn/', (err, stream3) => {
|
|
if (err) {
|
|
console.log('HTTPS测试失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream3.on('data', (data) => {
|
|
console.log('\nHTTPS响应:', data.toString());
|
|
});
|
|
|
|
stream3.on('close', () => {
|
|
conn.end();
|
|
});
|
|
});
|
|
}, 2000);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |