60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 修复Nginx容器 ===\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 -p 80:80 -v /www/huishou/nginx/conf.d:/etc/nginx/conf.d -v /www/huishou/dist:/usr/share/nginx/html 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'
|
|
}); |