| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | * @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()){ |
| | |
| | | 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(); |
| | |
| | | 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()); |
| | |
| | | * @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 { |
| | |
| | | } |
| | | // 执行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(); |