From 212e79b0d47d5d54498e1a635c3bae0e60a11908 Mon Sep 17 00:00:00 2001 From: linrf Date: Tue, 15 Aug 2023 09:33:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=88=E7=AB=AF=E9=87=8D=E5=90=AF=EF=BC=8C?= =?UTF-8?q?=E6=89=A7=E8=A1=8Cjenkins-update.bat=E8=84=9A=E6=9C=AC=EF=BC=88?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E4=BF=AE=E6=94=B9=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E5=91=BD=E4=BB=A4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/netty/client/NettyClient.java | 14 ++++++++++++-- .../netty/client/handler/ClientHandler.java | 10 +++++++++- .../server/common/utils/StartUpExeUtils.java | 18 ++++++++++++++---- .../src/main/resources/bootstrap.yml | 3 ++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/NettyClient.java b/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/NettyClient.java index 250d23d..887a3f8 100644 --- a/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/NettyClient.java +++ b/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/NettyClient.java @@ -1,6 +1,5 @@ package com.docus.server.common.netty.client; -import com.docus.core.util.json.JSON; import com.docus.server.common.CommMsg; import com.docus.server.common.netty.event.StartUpEvent; import com.docus.server.common.netty.server.CollectorChannelCacheMap; @@ -37,6 +36,9 @@ public class NettyClient { @Value("${spring.application.name}") private String appName; + @Value("${docus.terminal-restart-bat}") + private String terminalRestartBat; + private SocketChannel socketChannel; @Resource @@ -57,7 +59,7 @@ public class NettyClient { * @param message 消息内容 */ public void sendMessage(CommMsg message) { - boolean success = socketChannel.writeAndFlush(JSON.toJSON(message)).isSuccess(); + boolean success = socketChannel.writeAndFlush(message).isSuccess(); if (success) { log.info("发送消息成功"); } @@ -106,4 +108,12 @@ public class NettyClient { public String getSaveCollectorPackagePath() { return saveCollectorPackagePath; } + + public String getAppName() { + return this.appName; + } + + public String getTerminalRestartBat() { + return this.terminalRestartBat; + } } diff --git a/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/handler/ClientHandler.java b/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/handler/ClientHandler.java index 1093a21..b57bb09 100644 --- a/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/handler/ClientHandler.java +++ b/collector-terminal-management/src/main/java/com/docus/server/common/netty/client/handler/ClientHandler.java @@ -194,9 +194,17 @@ public class ClientHandler extends SimpleChannelInboundHandler terminatorRestartMsg = CommMsg.builder() + .content(result) + .messageTime(DateUtil.formatDateTime(new Date())) + .messageType(TERMINATOR_RESTART) + .build(); + + nettyClient.sendMessage(terminatorRestartMsg); } @Override diff --git a/collector-terminal-management/src/main/java/com/docus/server/common/utils/StartUpExeUtils.java b/collector-terminal-management/src/main/java/com/docus/server/common/utils/StartUpExeUtils.java index f95c1bb..869bc90 100644 --- a/collector-terminal-management/src/main/java/com/docus/server/common/utils/StartUpExeUtils.java +++ b/collector-terminal-management/src/main/java/com/docus/server/common/utils/StartUpExeUtils.java @@ -6,19 +6,29 @@ import java.io.InputStreamReader; public class StartUpExeUtils { - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { // startUpExeOnly("H:\\tools\\Navicat Premium 12免安装\\Navicat Premium 12\\navicat.exe"); // killExeOnly("navicat.exe"); // startUpExe("H:\\tools\\Navicat Premium 12免安装\\Navicat Premium 12\\navicat.exe", "navicat.exe"); - restartComputer(); + restartTerminal(""); } private static boolean startExeStatus = true;//exe启动状态 //重启终端 - public static void restartTerminal() throws IOException { - Runtime.getRuntime().exec("D:\\webroot\\collector-terminal-management\\jenkins-update.bat d:\\webroot"); + public static String restartTerminal(String bat) throws IOException, InterruptedException { + Process process = Runtime.getRuntime().exec(bat); + + int exitCode = process.waitFor(); + + if (exitCode == 0) { + System.out.println("Command executed successfully."); + return "Command executed successfully."; + } else { + System.out.println("Command execution failed."); + return "Command executed failed."; + } } //重启虚拟机 diff --git a/collector-terminal-management/src/main/resources/bootstrap.yml b/collector-terminal-management/src/main/resources/bootstrap.yml index 7769e6b..ef97e07 100644 --- a/collector-terminal-management/src/main/resources/bootstrap.yml +++ b/collector-terminal-management/src/main/resources/bootstrap.yml @@ -72,4 +72,5 @@ file: docus: vm-task-cron: 0/30 * * * * ? collector-package-download-url: http://192.168.16.110:9113 - collector-package-download-savePath: H:\\packages\\ \ No newline at end of file + collector-package-download-savePath: H:\\packages\\ + terminal-restart-bat: cmd /c start D:\webroot\collector-scheduling-management\jenkins-update.bat d:\webroot \ No newline at end of file