From 3c9e475bd8e0c7f2a45d3cd5857e9c8776e81f5d Mon Sep 17 00:00:00 2001 From: weibaohui Date: Wed, 8 Nov 2023 16:26:39 +0800 Subject: [PATCH] port copy open --- src/backend/k8s/shell/Shell.service.ts | 43 ++++++++++------- .../PortFoward/PortForwardActionView.vue | 47 ++++++++++++++++--- .../PortFoward/PortForwardListView.vue | 5 +- .../components/container/ContainersView.vue | 27 +++++++++-- src/frontend/components/pod/PodView.vue | 14 +++--- 5 files changed, 101 insertions(+), 35 deletions(-) diff --git a/src/backend/k8s/shell/Shell.service.ts b/src/backend/k8s/shell/Shell.service.ts index 1c1ddd1..0805079 100644 --- a/src/backend/k8s/shell/Shell.service.ts +++ b/src/backend/k8s/shell/Shell.service.ts @@ -108,31 +108,42 @@ export class ShellService { @Cron(CronExpression.EVERY_SECOND) cornCheckPortList() { this.shellList.forEach((d) => { - d.portForward.status = this.ncPort(d.portForward.localPort) - d.portForward.statusTimestamp = moment().local().toDate() - this.logger.log(`nc probe ${d.portForward.localPort}`) + this.ncPort(d.portForward.localPort, + () => { + d.portForward.status = 'succeeded' + d.portForward.statusTimestamp = moment().local().toDate() + // this.logger.log(`nc probe ${d.portForward.localPort} succeeded`) + }, + () => { + d.portForward.status = 'refused' + d.portForward.statusTimestamp = moment().local().toDate() + // this.logger.log(`nc probe ${d.portForward.localPort} refused`) + }) + + // this.logger.log(`nc probe ${d.portForward.localPort}`) }) } - ncPort(port: number) { - let result = 'refused' + ncPort(port: number, successCallback: () => void, refusedCallback: () => void) { const nc = spawn('nc', ['-v', '-w', '1', '-z', '127.0.0.1', `${port}`]) - // nc.on('close', (code, signal) => { - // this.logger.error( - // `child process terminated due to receipt of signal ${code} ${signal}`) - // }) + nc.on('close', (code, signal) => { + this.logger.log( + `nc probe ${port} end ${code} ${signal}`) + }) nc.stdout.on('data', (data) => { if (data.toString().includes('succeeded')) - result = 'succeeded' - // this.logger.error(data.toString()) + successCallback() + if (data.toString().includes('refused')) + refusedCallback() }) // - // nc.stderr.on('data', (data) => { - // this.logger.error(data.toString()) - // }) + nc.stderr.on('data', (data) => { + if (data.toString().includes('succeeded')) + successCallback() + if (data.toString().includes('refused')) + refusedCallback() + }) // Send SIGHUP to process. // nc.kill('SIGHUP') - - return result } } diff --git a/src/frontend/components/PortFoward/PortForwardActionView.vue b/src/frontend/components/PortFoward/PortForwardActionView.vue index 5e1439c..02a5208 100644 --- a/src/frontend/components/PortFoward/PortForwardActionView.vue +++ b/src/frontend/components/PortFoward/PortForwardActionView.vue @@ -1,7 +1,7 @@