From 38dd8dc74aeb3a7599be28ad602c8f4e2a9afe52 Mon Sep 17 00:00:00 2001 From: Arno Date: Tue, 13 Aug 2019 11:15:22 +0800 Subject: [PATCH] =?UTF-8?q?nginx=E9=87=8D=E6=96=B0=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpom/controller/system/NginxController.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/agent/src/main/java/cn/keepbx/jpom/controller/system/NginxController.java b/modules/agent/src/main/java/cn/keepbx/jpom/controller/system/NginxController.java index 663b55952..e80088b69 100644 --- a/modules/agent/src/main/java/cn/keepbx/jpom/controller/system/NginxController.java +++ b/modules/agent/src/main/java/cn/keepbx/jpom/controller/system/NginxController.java @@ -284,11 +284,8 @@ public class NginxController extends BaseAgentController { public String reload() { if (SystemUtil.getOsInfo().isLinux()) { String result = CommandUtil.execSystemCommand("nginx -t"); - List strings = StrSpliter.splitTrim(result, "\n", true); - for (String str : strings) { - if (!str.endsWith("successful") || !str.endsWith("ok")) { - return JsonMessage.getString(400, result); - } + if (!result.endsWith("successful") || !result.endsWith("ok")) { + return JsonMessage.getString(400, result); } CommandUtil.execSystemCommand("nginx -s reload"); } else if (SystemUtil.getOsInfo().isWindows()) { @@ -297,22 +294,20 @@ public class NginxController extends BaseAgentController { String result = CommandUtil.execSystemCommand("sc qc " + name); List strings = StrSpliter.splitTrim(result, "\n", true); //服务路径 - String path = ""; + File file = null; for (String str : strings) { str = str.toUpperCase().trim(); if (str.startsWith("BINARY_PATH_NAME")) { - path = str.substring(str.indexOf(":") + 1).replace("\"", ""); + String path = str.substring(str.indexOf(":") + 1).replace("\"", "").trim(); + file = FileUtil.file(path).getParentFile(); break; } } - if (StrUtil.isEmpty(path)) { - return JsonMessage.getString(400, "未找到nginx路径"); - } - File file = FileUtil.file(path).getParentFile(); result = CommandUtil.execSystemCommand("nginx -t", file); if (StrUtil.isNotEmpty(result)) { return JsonMessage.getString(400, result); } + CommandUtil.execSystemCommand("nginx -s reload", file); } return JsonMessage.getString(200, "重新加载成功"); }