|
@@ -25,25 +25,38 @@ const getConfig = () => {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
const execRemoteCommand = async () => {
|
|
const execRemoteCommand = async () => {
|
|
const config = getConfig();
|
|
const config = getConfig();
|
|
const conn = new ssh2.Client();
|
|
const conn = new ssh2.Client();
|
|
|
|
+
|
|
conn.on("ready", function () {
|
|
conn.on("ready", function () {
|
|
- console.log(chalk.blue("ssh2 链接成功 - 执行 pm2 restart bigModelAdmin"));
|
|
|
|
- conn.exec("pm2 restart bigModelAdmin", function (err, stream) {
|
|
|
|
|
|
+ console.log(chalk.blue("ssh2 链接成功"));
|
|
|
|
+
|
|
|
|
+ const commands = [
|
|
|
|
+ 'cd /data/node_web/modelAdmin',
|
|
|
|
+ 'pwd',
|
|
|
|
+ 'pm2 list',
|
|
|
|
+ 'pm2 del bigModelAdmin',
|
|
|
|
+ 'pm2 start'
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ conn.exec(commands.join(";"), { pty: true }, function (err, stream) {
|
|
if (err) throw err;
|
|
if (err) throw err;
|
|
- console.log(
|
|
|
|
- chalk.blue(``) + chalk.green(`---执行成功---`),
|
|
|
|
- );
|
|
|
|
- console.log(
|
|
|
|
- chalk.blue(`✅`) + chalk.green(`---部署完成---`),
|
|
|
|
- );
|
|
|
|
- conn.end();
|
|
|
|
|
|
+ stream
|
|
|
|
+ .on('close', function (code, signal) {
|
|
|
|
+ console.log('Command 执行成功');
|
|
|
|
+ conn.end(); // 结束SSH连接
|
|
|
|
+ })
|
|
|
|
+ .on('data', function (data) {
|
|
|
|
+ process.stdout.write(data);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ stream.stdin.end();
|
|
});
|
|
});
|
|
}).connect({ ...config });
|
|
}).connect({ ...config });
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// 部署
|
|
// 部署
|
|
const connectShell = async () => {
|
|
const connectShell = async () => {
|
|
const sftp = new Client();
|
|
const sftp = new Client();
|
|
@@ -79,11 +92,11 @@ const connectShell = async () => {
|
|
spinner.info('文件上传结束')
|
|
spinner.info('文件上传结束')
|
|
spinner.stop();
|
|
spinner.stop();
|
|
|
|
|
|
- if (filterStage === 'prod') {
|
|
|
|
- execRemoteCommand()
|
|
|
|
- }
|
|
|
|
|
|
+ // if (filterStage === 'prod') {
|
|
|
|
+ execRemoteCommand()
|
|
|
|
+ // }
|
|
|
|
|
|
- printMsg({ color: 'green', text: '上传完成,部署成功' });
|
|
|
|
|
|
+ printMsg({ color: 'green', text: '上传完成,准备指令中' });
|
|
sftp.end();
|
|
sftp.end();
|
|
})
|
|
})
|
|
.catch((err) => {
|
|
.catch((err) => {
|