Files
huishou/fix-port.mjs
T
2026-07-27 14:07:26 +08:00

60 lines
1.6 KiB
JavaScript

import { Client } from 'ssh2';
const conn = new Client();
conn.on('ready', () => {
console.log('=== 修改端口为80 ===\n');
conn.exec('docker stop huishou && docker rm huishou', (err, stream) => {
if (err) {
console.log('删除容器失败:', err.message);
conn.end();
return;
}
stream.on('close', () => {
console.log('容器已删除');
conn.exec('docker run -d --name huishou --network bridge -p 80:80 -v /www/huishou/admin:/usr/share/nginx/html/admin -v /www/huishou/dist/build/h5:/usr/share/nginx/html/h5 -v /www/huishou/admin/nginx.conf:/etc/nginx/conf.d/default.conf nginx:latest', (err, stream2) => {
if (err) {
console.log('启动容器失败:', err.message);
conn.end();
return;
}
stream2.on('close', () => {
console.log('容器启动中...');
setTimeout(() => {
conn.exec('docker ps | grep huishou', (err, stream3) => {
if (err) {
console.log('检查容器失败:', err.message);
conn.end();
return;
}
stream3.on('data', (data) => {
console.log('\n容器状态:', data.toString());
});
stream3.on('close', () => {
conn.end();
});
});
}, 3000);
});
});
});
});
});
conn.on('error', (err) => {
console.log('连接错误:', err.message);
});
conn.connect({
host: 'hs.yifenbao.cn',
port: 22,
username: 'root',
password: 'Torch1112'
});