From 702657b9e1d73c8c26cafbc64b3284f121ad2b58 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期一, 04 三月 2024 22:25:37 +0800
Subject: [PATCH] 远程部署功能完善,并在本地测试成功。
---
Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java | 35 +++++++++++++++++++++++++----------
Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/IDeployAppsService.java | 2 +-
Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/controller/DeployAppsController.java | 2 +-
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/controller/DeployAppsController.java b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/controller/DeployAppsController.java
index 133fd58..ac00e01 100644
--- a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/controller/DeployAppsController.java
+++ b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/controller/DeployAppsController.java
@@ -96,7 +96,7 @@
if(Func.isBlank(serverName)){
return R.fail("Mandatory parameter service name not found!");
}
- return deployAppsService.importClassify(files,serverName);
+ return deployAppsService.importJarUpdate(files,serverName);
}
/**
diff --git a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/IDeployAppsService.java b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/IDeployAppsService.java
index cfa7375..3538c88 100644
--- a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/IDeployAppsService.java
+++ b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/IDeployAppsService.java
@@ -56,7 +56,7 @@
* @param serverName
* @return
*/
- R importClassify(MultipartFile[] files, String serverName) throws ServiceException;
+ R importJarUpdate(MultipartFile[] files, String serverName) throws ServiceException;
/**
* 鎵ц鍛戒护
diff --git a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java
index 6ac5349..7785b88 100644
--- a/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-deploy/src/main/java/com/vci/ubcs/deploy/service/impl/DeployAppsServiceImpl.java
@@ -15,6 +15,7 @@
import com.vci.ubcs.deploy.service.IDeployAppsService;
import com.vci.ubcs.deploy.vo.DeployAppsVO;
import com.vci.ubcs.starter.util.HttpUtils;
+import jodd.io.StreamGobbler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
@@ -39,7 +40,9 @@
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
+import java.net.InetAddress;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -228,7 +231,7 @@
* @return
*/
@Override
- public R importClassify(MultipartFile[] files, String serverName) throws ServiceException {
+ public R importJarUpdate(MultipartFile[] files, String serverName) throws ServiceException {
// 鏍规嵁鏈嶅姟鍚嶆煡鐪嬪埌鏈嶅姟鐩稿叧淇℃伅
List<DeployApps> deployAppsDB = deployAppsMapper.selectList(Wrappers.<DeployApps>query().lambda().eq(DeployApps::getServerName, serverName));
if(deployAppsDB.isEmpty()){
@@ -297,7 +300,7 @@
file1.delete();
}
}
- String output = excute(deployAppsDB.get(0),"UP");
+ String output = execute(deployAppsDB.get(0),"UP");
return R.success(output.toString());
} catch (IOException e) {
e.printStackTrace();
@@ -320,7 +323,7 @@
if(deployAppsDB.isEmpty()){
return R.fail("鍛戒护鎵ц鍑洪敊锛屽簱涓湭鎵惧埌"+ deployAppsVO.getName() +"鏈嶅姟鐩稿叧閰嶇疆锛�" );
}
- excuteRes = excute(deployAppsDB.get(0),deployAppsVO.getStatus());
+ excuteRes = execute(deployAppsDB.get(0),deployAppsVO.getStatus());
return R.success("鍛戒护鎵ц缁撴潫锛�"+excuteRes);
}catch (Exception e){
throw new ServiceException(e.getMessage());
@@ -333,7 +336,7 @@
* @return
* @throws ServiceException
*/
- private String excute(DeployApps deployApps,String type) throws ServiceException {
+ public String execute(DeployApps deployApps,String type) throws ServiceException {
// 澶勭悊涓婁紶鏂囦欢鐨勯�昏緫
StringBuilder output = new StringBuilder();
try {
@@ -348,25 +351,37 @@
}
// 鎵цLinux鍛戒护
log.info("寮�濮嬫墽琛屽懡浠わ細"+cmd);
- Process process = Runtime.getRuntime().exec(cmd);
+ // Process process = Runtime.getRuntime().exec(cmd);
+ ProcessBuilder processBuilder = new ProcessBuilder(cmd.split("\\s"));
+ // processBuilder.command(cmd);
+ Process process = processBuilder.start();
+ // 绛夊緟鍛戒护鎵ц瀹屾垚
+ int exitCode = process.waitFor();
+
+ InputStream inputStream = process.getInputStream();
+ OutputStream outputStream = process.getOutputStream();
+ InputStream errorStream = process.getErrorStream();
// 璇诲彇鍛戒护鎵ц缁撴灉
- BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
- // 绛夊緟鍛戒护鎵ц瀹屾垚
- int exitCode = process.waitFor();
+ reader.close();
+
// 璇诲彇鍛戒护鎵ц鐨勯敊璇緭鍑烘祦
- BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+ BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream));
StringBuilder errorOutput = new StringBuilder();
String errorLine;
while ((errorLine = errorReader.readLine()) != null) {
errorOutput.append(errorLine).append("\n");
}
String errorOutputString = errorOutput.toString();
+ errorReader.close();
+
log.info("閿欒杈撳嚭锛�" + errorOutputString);
- log.info("鍛戒护鎵ц缁撴灉锛�" + output.toString()+":"+exitCode);
+ int exitValue = process.exitValue();
+ log.info("鍛戒护鎵ц缁撴灉锛�" + output.toString()+":"+exitCode+","+exitValue);
return output.toString();
}catch (IOException | InterruptedException e){
e.printStackTrace();
--
Gitblit v1.9.3