nginx重新加载

This commit is contained in:
Arno 2019-08-13 11:15:22 +08:00
parent 9df05bdce3
commit 38dd8dc74a

View File

@ -284,12 +284,9 @@ public class NginxController extends BaseAgentController {
public String reload() { public String reload() {
if (SystemUtil.getOsInfo().isLinux()) { if (SystemUtil.getOsInfo().isLinux()) {
String result = CommandUtil.execSystemCommand("nginx -t"); String result = CommandUtil.execSystemCommand("nginx -t");
List<String> strings = StrSpliter.splitTrim(result, "\n", true); if (!result.endsWith("successful") || !result.endsWith("ok")) {
for (String str : strings) {
if (!str.endsWith("successful") || !str.endsWith("ok")) {
return JsonMessage.getString(400, result); return JsonMessage.getString(400, result);
} }
}
CommandUtil.execSystemCommand("nginx -s reload"); CommandUtil.execSystemCommand("nginx -s reload");
} else if (SystemUtil.getOsInfo().isWindows()) { } else if (SystemUtil.getOsInfo().isWindows()) {
JSONObject ngxConf = nginxService.getNgxConf(); JSONObject ngxConf = nginxService.getNgxConf();
@ -297,22 +294,20 @@ public class NginxController extends BaseAgentController {
String result = CommandUtil.execSystemCommand("sc qc " + name); String result = CommandUtil.execSystemCommand("sc qc " + name);
List<String> strings = StrSpliter.splitTrim(result, "\n", true); List<String> strings = StrSpliter.splitTrim(result, "\n", true);
//服务路径 //服务路径
String path = ""; File file = null;
for (String str : strings) { for (String str : strings) {
str = str.toUpperCase().trim(); str = str.toUpperCase().trim();
if (str.startsWith("BINARY_PATH_NAME")) { 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; break;
} }
} }
if (StrUtil.isEmpty(path)) {
return JsonMessage.getString(400, "未找到nginx路径");
}
File file = FileUtil.file(path).getParentFile();
result = CommandUtil.execSystemCommand("nginx -t", file); result = CommandUtil.execSystemCommand("nginx -t", file);
if (StrUtil.isNotEmpty(result)) { if (StrUtil.isNotEmpty(result)) {
return JsonMessage.getString(400, result); return JsonMessage.getString(400, result);
} }
CommandUtil.execSystemCommand("nginx -s reload", file);
} }
return JsonMessage.getString(200, "重新加载成功"); return JsonMessage.getString(200, "重新加载成功");
} }