diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/PathUtils.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/PathUtils.java index fba5569b..491bdf09 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/PathUtils.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/utils/PathUtils.java @@ -19,25 +19,34 @@ public class PathUtils { /** * 获取用户根目录 * - * @param username 用户名 + * @param isWindows isWindows + * @param username 用户名 * @return 用户目录 */ - public static String getHomePath(String username) { - if (Const.ROOT.equals(username)) { - return "/" + Const.ROOT; + public static String getHomePath(boolean isWindows, String username) { + if (isWindows) { + // windows + return "C:/Users/" + username; } else { - return "/home/" + username; + // linux + if (Const.ROOT.equals(username)) { + return "/" + Const.ROOT; + } else { + return "/home/" + username; + } } } + /** * 获取应用路径 * - * @param username username + * @param isWindows isWindows + * @param username username * @return path */ - public static String getAppPath(String username) { - return getHomePath(username) + public static String getAppPath(boolean isWindows, String username) { + return getHomePath(isWindows, username) + "/" + AppConst.ORION + "/" + AppConst.ORION_OPS_PRO; } @@ -45,12 +54,13 @@ public class PathUtils { /** * 构建应用路径 * - * @param username username - * @param paths paths + * @param isWindows isWindows, + * @param username username + * @param paths paths * @return path */ - public static String buildAppPath(String username, Object... paths) { - StringBuilder path = new StringBuilder(getAppPath(username)); + public static String buildAppPath(boolean isWindows, String username, Object... paths) { + StringBuilder path = new StringBuilder(getAppPath(isWindows, username)); for (Object o : paths) { path.append("/").append(Objects1.toString(o)); } diff --git a/orion-ops-launch/src/main/resources/application.yaml b/orion-ops-launch/src/main/resources/application.yaml index 14447be7..b4ea3092 100644 --- a/orion-ops-launch/src/main/resources/application.yaml +++ b/orion-ops-launch/src/main/resources/application.yaml @@ -84,8 +84,7 @@ spring: tablePrefix: QRTZ_ misfireThreshold: 60000 clusterCheckinInterval: 5000 - # 打开群集功能 - isClustered: false + isClustered: true #连接池 threadPool: class: org.quartz.simpl.SimpleThreadPool diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/exec/command/handler/ExecCommandHandler.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/exec/command/handler/ExecCommandHandler.java index 864397b2..9531aebc 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/exec/command/handler/ExecCommandHandler.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/exec/command/handler/ExecCommandHandler.java @@ -146,11 +146,18 @@ public class ExecCommandHandler implements IExecCommandHandler { // 打开 sftp sftpExecutor = sessionStore.getSftpExecutor(execHostCommand.getFileNameCharset()); sftpExecutor.connect(); - // 上传文件 + // 必须要以 / 开头 + String scriptPath = execHostCommand.getScriptPath(); + if (!scriptPath.startsWith("/")) { + scriptPath = "/" + scriptPath; + } + // 创建文件 + sftpExecutor.touch(scriptPath); + // 写入命令 byte[] command = Strings.replaceCRLF(execHostCommand.getCommand()).getBytes(execHostCommand.getFileContentCharset()); - sftpExecutor.write(execHostCommand.getScriptPath(), command); + sftpExecutor.write(scriptPath, command); // 修改权限 - sftpExecutor.changeMode(execHostCommand.getScriptPath(), 777); + sftpExecutor.changeMode(scriptPath, 777); } catch (Exception e) { throw Exceptions.sftp(e); } finally { diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/transfer/TransferMessageDispatcher.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/transfer/TransferMessageDispatcher.java index 9d90f4f6..384b248b 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/transfer/TransferMessageDispatcher.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/handler/host/transfer/TransferMessageDispatcher.java @@ -56,7 +56,7 @@ public class TransferMessageDispatcher extends AbstractWebSocketHandler { String id = session.getId(); log.info("TransferMessageHandler-afterConnectionClosed id: {}, code: {}, reason: {}", id, status.getCode(), status.getReason()); // 关闭会话 - Streams.close(handlers.get(id)); + Streams.close(handlers.remove(id)); } } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecCommandServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecCommandServiceImpl.java index 9226d1bb..c24573f3 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecCommandServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/ExecCommandServiceImpl.java @@ -349,11 +349,12 @@ public class ExecCommandServiceImpl implements ExecCommandService { * @return scriptPath */ private String buildScriptPath(String username, String osType, Long logId, Long hostId) { + HostSshOsTypeEnum os = HostSshOsTypeEnum.of(osType); String name = PathConst.EXEC + "_" + logId + "_" + hostId - + HostSshOsTypeEnum.of(osType).getScriptSuffix(); - return PathUtils.buildAppPath(username, PathConst.SCRIPT, name); + + os.getScriptSuffix(); + return PathUtils.buildAppPath(HostSshOsTypeEnum.WINDOWS.equals(os), username, PathConst.SCRIPT, name); } } diff --git a/orion-ops-ui/src/views/asset/host-list/components/config/host-config-drawer.vue b/orion-ops-ui/src/views/asset/host-list/components/config/host-config-drawer.vue index b154cffd..9ea24856 100644 --- a/orion-ops-ui/src/views/asset/host-list/components/config/host-config-drawer.vue +++ b/orion-ops-ui/src/views/asset/host-list/components/config/host-config-drawer.vue @@ -1,6 +1,6 @@