mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-30 10:58:14 +08:00
修护项目配置 webhook 后无法关闭进程的情况
This commit is contained in:
parent
79da259acf
commit
3c5fc255a7
@ -19,6 +19,7 @@
|
||||
7. 【server】优化 ssh 安装插件端,不输入节点ID、没有配置权限报错(感谢@大土豆)
|
||||
8. 【agent】修护项目 `JavaExtDirsCp` 模式加载非 Jar 文件问题(感谢@大灰灰)
|
||||
9. 升级 SpringBoot 版本 2.6.1
|
||||
10. 【agent】修护项目配置 webhook 后无法关闭进程的情况(感谢@大土豆)
|
||||
|
||||
------
|
||||
|
||||
|
@ -132,7 +132,7 @@ yum install -y wget && wget -O install.sh https://dromara.gitee.io/jpom/docs/ins
|
||||
> 特别提醒:一键安装的时候注意执行命令不可在同一目录下,即Server端和Agent端不可安装在同一目录下
|
||||
>
|
||||
> 如无法访问,检查下是否开启了防火墙`systemctl status firewalld`,如状态显示为绿色`Active: active (running)`可临时关闭防火墙`systemctl stop firewalld`,然后重启防火墙`firewall-cmd --reload`(建议仅测试环境下使用,生产环境下慎用)
|
||||
> 如关闭防火墙后仍无法访问,并且使用的是云服务器,还需要到云服务器管理后台中关闭防火墙
|
||||
> 如关闭防火墙后仍无法访问,并且使用的是云服务器,还需要到云服务器管理后台中检查安全组规则(关闭防火墙)
|
||||
|
||||
### 容器化安装
|
||||
> 注意:容器化安装方式需要先安装docker
|
||||
|
@ -29,6 +29,7 @@ import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.JarClassLoader;
|
||||
import cn.hutool.core.lang.Tuple;
|
||||
import cn.hutool.core.text.CharPool;
|
||||
import cn.hutool.core.text.StrSplitter;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
@ -187,12 +188,18 @@ public abstract class AbstractProjectCommander {
|
||||
* @return 结果
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
|
||||
public abstract String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception;
|
||||
|
||||
/**
|
||||
* 停止之前
|
||||
*
|
||||
* @param nodeProjectInfoModel 项目
|
||||
* @return 结果
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public Tuple stopBefore(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
String beforeStop = this.webHooks(nodeProjectInfoModel, javaCopyItem, "beforeStop");
|
||||
if (StrUtil.isNotEmpty(beforeStop)) {
|
||||
return beforeStop;
|
||||
}
|
||||
// 再次查看进程信息
|
||||
String result = status(tag);
|
||||
//
|
||||
@ -204,7 +211,7 @@ public abstract class AbstractProjectCommander {
|
||||
PID_PORT.remove(pid);
|
||||
}
|
||||
this.asyncWebHooks(nodeProjectInfoModel, javaCopyItem, "stop", "result", result);
|
||||
return result;
|
||||
return new Tuple(StrUtil.emptyToDefault(beforeStop, StrUtil.EMPTY), result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,16 +570,16 @@ public abstract class AbstractProjectCommander {
|
||||
* 阻塞检查程序状态
|
||||
* @param tag 程序tag
|
||||
* @param status 要检查的状态
|
||||
* @throws Exception 异常
|
||||
*
|
||||
* @return 和参数status相反
|
||||
*/
|
||||
protected boolean loopCheckRun(String tag, boolean status) throws Exception {
|
||||
protected boolean loopCheckRun(String tag, boolean status) {
|
||||
int stopWaitTime = AgentExtConfigBean.getInstance().getStopWaitTime();
|
||||
stopWaitTime = Math.max(stopWaitTime, 1);
|
||||
int loopCount = (int) (TimeUnit.SECONDS.toMillis(stopWaitTime) / 500);
|
||||
int count = 0;
|
||||
do {
|
||||
if (isRun(tag) == status) {
|
||||
if (this.isRun(tag) == status) {
|
||||
return status;
|
||||
}
|
||||
ThreadUtil.sleep(500);
|
||||
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Code Technology Studio
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.jpom.common.commander;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Tuple;
|
||||
import cn.hutool.core.text.StrSplitter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jpom.model.data.NodeProjectInfoModel;
|
||||
import io.jpom.model.system.NetstatModel;
|
||||
import io.jpom.util.CommandUtil;
|
||||
import io.jpom.util.JvmUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* unix
|
||||
*
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/12/17
|
||||
*/
|
||||
public abstract class BaseUnixProjectCommander extends AbstractProjectCommander {
|
||||
|
||||
|
||||
@Override
|
||||
public String buildCommand(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) {
|
||||
String path = NodeProjectInfoModel.getClassPathLib(nodeProjectInfoModel);
|
||||
if (StrUtil.isBlank(path)) {
|
||||
return null;
|
||||
}
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
return String.format("nohup %s %s %s" +
|
||||
" %s %s %s >> %s 2>&1 &",
|
||||
getRunJavaPath(nodeProjectInfoModel, false),
|
||||
javaCopyItem == null ? nodeProjectInfoModel.getJvm() : javaCopyItem.getJvm(),
|
||||
JvmUtil.getJpomPidTag(tag, nodeProjectInfoModel.allLib()),
|
||||
path,
|
||||
nodeProjectInfoModel.getMainClass(),
|
||||
javaCopyItem == null ? nodeProjectInfoModel.getArgs() : javaCopyItem.getArgs(),
|
||||
nodeProjectInfoModel.getAbsoluteLog(javaCopyItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
|
||||
Tuple tuple = super.stopBefore(nodeProjectInfoModel, javaCopyItem);
|
||||
String result = tuple.get(1);
|
||||
String webHook = tuple.get(0);
|
||||
int pid = parsePid(result);
|
||||
if (pid > 0) {
|
||||
File file = FileUtil.file(nodeProjectInfoModel.allLib());
|
||||
String kill = AbstractSystemCommander.getInstance().kill(file, pid);
|
||||
if (this.loopCheckRun(nodeProjectInfoModel.getId(), false)) {
|
||||
// 强制杀进程
|
||||
String cmd = String.format("kill -9 %s", pid);
|
||||
CommandUtil.asyncExeLocalCommand(file, cmd);
|
||||
}
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
result = status(tag) + StrUtil.SPACE + kill;
|
||||
}
|
||||
return StrUtil.format("{} {}", result, webHook);
|
||||
}
|
||||
|
||||
protected List<NetstatModel> listNetstat(String cmd) {
|
||||
String result = CommandUtil.execSystemCommand(cmd);
|
||||
List<String> netList = StrSplitter.splitTrim(result, StrUtil.LF, true);
|
||||
if (CollUtil.isEmpty(netList)) {
|
||||
return null;
|
||||
}
|
||||
return netList.stream().map(str -> {
|
||||
List<String> list = StrSplitter.splitTrim(str, " ", true);
|
||||
if (list.size() < 5) {
|
||||
return null;
|
||||
}
|
||||
NetstatModel netstatModel = new NetstatModel();
|
||||
netstatModel.setProtocol(list.get(0));
|
||||
netstatModel.setReceive(list.get(1));
|
||||
netstatModel.setSend(list.get(2));
|
||||
netstatModel.setLocal(list.get(3));
|
||||
netstatModel.setForeign(list.get(4));
|
||||
if ("tcp".equalsIgnoreCase(netstatModel.getProtocol())) {
|
||||
netstatModel.setStatus(CollUtil.get(list, 5));
|
||||
netstatModel.setName(CollUtil.get(list, 6));
|
||||
} else {
|
||||
netstatModel.setStatus(StrUtil.DASHED);
|
||||
netstatModel.setName(CollUtil.get(list, 5));
|
||||
}
|
||||
|
||||
return netstatModel;
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -22,18 +22,9 @@
|
||||
*/
|
||||
package io.jpom.common.commander.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.text.StrSplitter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
import io.jpom.common.commander.AbstractSystemCommander;
|
||||
import io.jpom.model.data.NodeProjectInfoModel;
|
||||
import io.jpom.common.commander.BaseUnixProjectCommander;
|
||||
import io.jpom.model.system.NetstatModel;
|
||||
import io.jpom.util.CommandUtil;
|
||||
import io.jpom.util.JvmUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -41,77 +32,16 @@ import java.util.List;
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
public class LinuxProjectCommander extends AbstractProjectCommander {
|
||||
public class LinuxProjectCommander extends BaseUnixProjectCommander {
|
||||
|
||||
@Override
|
||||
public String buildCommand(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) {
|
||||
String path = NodeProjectInfoModel.getClassPathLib(nodeProjectInfoModel);
|
||||
if (StrUtil.isBlank(path)) {
|
||||
return null;
|
||||
}
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
return String.format("nohup %s %s %s" +
|
||||
" %s %s %s >> %s 2>&1 &",
|
||||
getRunJavaPath(nodeProjectInfoModel, false),
|
||||
javaCopyItem == null ? nodeProjectInfoModel.getJvm() : javaCopyItem.getJvm(),
|
||||
JvmUtil.getJpomPidTag(tag, nodeProjectInfoModel.allLib()),
|
||||
path,
|
||||
nodeProjectInfoModel.getMainClass(),
|
||||
javaCopyItem == null ? nodeProjectInfoModel.getArgs() : javaCopyItem.getArgs(),
|
||||
nodeProjectInfoModel.getAbsoluteLog(javaCopyItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
|
||||
String result = super.stop(nodeProjectInfoModel, javaCopyItem);
|
||||
int pid = parsePid(result);
|
||||
if (pid > 0) {
|
||||
String kill = AbstractSystemCommander.getInstance().kill(FileUtil.file(nodeProjectInfoModel.allLib()), pid);
|
||||
if (loopCheckRun(nodeProjectInfoModel.getId(), false)) {
|
||||
// 强制杀进程
|
||||
String cmd = String.format("kill -9 %s", pid);
|
||||
CommandUtil.asyncExeLocalCommand(FileUtil.file(nodeProjectInfoModel.allLib()), cmd);
|
||||
}
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
result = status(tag) + StrUtil.SPACE + kill;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetstatModel> listNetstat(int pId, boolean listening) {
|
||||
String cmd;
|
||||
if (listening) {
|
||||
cmd = "netstat -antup | grep " + pId + " |grep \"LISTEN\" | head -20";
|
||||
} else {
|
||||
cmd = "netstat -antup | grep " + pId + " |grep -v \"CLOSE_WAIT\" | head -20";
|
||||
}
|
||||
String result = CommandUtil.execSystemCommand(cmd);
|
||||
List<String> netList = StrSplitter.splitTrim(result, "\n", true);
|
||||
if (netList == null || netList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
List<NetstatModel> array = new ArrayList<>();
|
||||
for (String str : netList) {
|
||||
List<String> list = StrSplitter.splitTrim(str, " ", true);
|
||||
if (list.size() < 5) {
|
||||
continue;
|
||||
}
|
||||
NetstatModel netstatModel = new NetstatModel();
|
||||
netstatModel.setProtocol(list.get(0));
|
||||
netstatModel.setReceive(list.get(1));
|
||||
netstatModel.setSend(list.get(2));
|
||||
netstatModel.setLocal(list.get(3));
|
||||
netstatModel.setForeign(list.get(4));
|
||||
if ("tcp".equalsIgnoreCase(netstatModel.getProtocol())) {
|
||||
netstatModel.setStatus(CollUtil.get(list, 5));
|
||||
netstatModel.setName(CollUtil.get(list, 6));
|
||||
} else {
|
||||
netstatModel.setStatus(StrUtil.DASHED);
|
||||
netstatModel.setName(CollUtil.get(list, 5));
|
||||
}
|
||||
array.add(netstatModel);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@Override
|
||||
public List<NetstatModel> listNetstat(int pId, boolean listening) {
|
||||
String cmd;
|
||||
if (listening) {
|
||||
cmd = "netstat -antup | grep " + pId + " |grep \"LISTEN\" | head -20";
|
||||
} else {
|
||||
cmd = "netstat -antup | grep " + pId + " |grep -v \"CLOSE_WAIT\" | head -20";
|
||||
}
|
||||
return super.listNetstat(cmd);
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,9 @@
|
||||
*/
|
||||
package io.jpom.common.commander.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.text.StrSplitter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
import io.jpom.common.commander.AbstractSystemCommander;
|
||||
import io.jpom.model.data.NodeProjectInfoModel;
|
||||
import io.jpom.common.commander.BaseUnixProjectCommander;
|
||||
import io.jpom.model.system.NetstatModel;
|
||||
import io.jpom.util.CommandUtil;
|
||||
import io.jpom.util.JvmUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -43,25 +34,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Hotstrip
|
||||
*/
|
||||
public class MacOsProjectCommander extends AbstractProjectCommander {
|
||||
|
||||
@Override
|
||||
public String buildCommand(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) {
|
||||
String path = NodeProjectInfoModel.getClassPathLib(nodeProjectInfoModel);
|
||||
if (StrUtil.isBlank(path)) {
|
||||
return null;
|
||||
}
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
return String.format("nohup %s %s %s" +
|
||||
" %s %s %s >> %s 2>&1 &",
|
||||
getRunJavaPath(nodeProjectInfoModel, false),
|
||||
javaCopyItem == null ? nodeProjectInfoModel.getJvm() : javaCopyItem.getJvm(),
|
||||
JvmUtil.getJpomPidTag(tag, nodeProjectInfoModel.allLib()),
|
||||
path,
|
||||
nodeProjectInfoModel.getMainClass(),
|
||||
javaCopyItem == null ? nodeProjectInfoModel.getArgs() : javaCopyItem.getArgs(),
|
||||
nodeProjectInfoModel.getAbsoluteLog(javaCopyItem));
|
||||
}
|
||||
public class MacOsProjectCommander extends BaseUnixProjectCommander {
|
||||
|
||||
@Override
|
||||
public List<NetstatModel> listNetstat(int pId, boolean listening) {
|
||||
@ -71,50 +44,6 @@ public class MacOsProjectCommander extends AbstractProjectCommander {
|
||||
} else {
|
||||
cmd = "lsof -n -P -iTCP -sTCP:CLOSE_WAIT |grep " + pId + " | head -20";
|
||||
}
|
||||
String result = CommandUtil.execSystemCommand(cmd);
|
||||
//DefaultSystemLog.getLog().debug("Mac OS lsof data: {}", result);
|
||||
List<String> netList = StrSplitter.splitTrim(result, "\n", true);
|
||||
if (netList == null || netList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
List<NetstatModel> array = new ArrayList<>();
|
||||
for (String str : netList) {
|
||||
List<String> list = StrSplitter.splitTrim(str, " ", true);
|
||||
if (list.size() < 5) {
|
||||
continue;
|
||||
}
|
||||
NetstatModel netstatModel = new NetstatModel();
|
||||
netstatModel.setProtocol(list.get(0));
|
||||
netstatModel.setReceive(list.get(1));
|
||||
netstatModel.setSend(list.get(2));
|
||||
netstatModel.setLocal(list.get(3));
|
||||
netstatModel.setForeign(list.get(4));
|
||||
if ("tcp".equalsIgnoreCase(netstatModel.getProtocol())) {
|
||||
netstatModel.setStatus(CollUtil.get(list, 5));
|
||||
netstatModel.setName(CollUtil.get(list, 6));
|
||||
} else {
|
||||
netstatModel.setStatus(StrUtil.DASHED);
|
||||
netstatModel.setName(CollUtil.get(list, 5));
|
||||
}
|
||||
array.add(netstatModel);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
|
||||
String result = super.stop(nodeProjectInfoModel, javaCopyItem);
|
||||
int pid = parsePid(result);
|
||||
if (pid > 0) {
|
||||
String kill = AbstractSystemCommander.getInstance().kill(FileUtil.file(nodeProjectInfoModel.allLib()), pid);
|
||||
if (loopCheckRun(nodeProjectInfoModel.getId(), false)) {
|
||||
// 强制杀进程
|
||||
String cmd = String.format("kill -9 %s", pid);
|
||||
CommandUtil.asyncExeLocalCommand(FileUtil.file(nodeProjectInfoModel.allLib()), cmd);
|
||||
}
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
result = status(tag) + StrUtil.SPACE + kill;
|
||||
}
|
||||
return result;
|
||||
return super.listNetstat(cmd);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package io.jpom.common.commander.impl;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Tuple;
|
||||
import cn.hutool.core.text.StrSplitter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
@ -42,65 +43,67 @@ import java.util.List;
|
||||
*/
|
||||
public class WindowsProjectCommander extends AbstractProjectCommander {
|
||||
|
||||
@Override
|
||||
public String buildCommand(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) {
|
||||
String classPath = NodeProjectInfoModel.getClassPathLib(nodeProjectInfoModel);
|
||||
if (StrUtil.isBlank(classPath)) {
|
||||
return null;
|
||||
}
|
||||
// 拼接命令
|
||||
String jvm = javaCopyItem == null ? nodeProjectInfoModel.getJvm() : javaCopyItem.getJvm();
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
String mainClass = nodeProjectInfoModel.getMainClass();
|
||||
String args = javaCopyItem == null ? nodeProjectInfoModel.getArgs() : javaCopyItem.getArgs();
|
||||
return String.format("%s %s %s " +
|
||||
"%s %s %s >> %s &",
|
||||
getRunJavaPath(nodeProjectInfoModel, true),
|
||||
jvm, JvmUtil.getJpomPidTag(tag, nodeProjectInfoModel.allLib()),
|
||||
classPath, mainClass, args, nodeProjectInfoModel.getAbsoluteLog(javaCopyItem));
|
||||
}
|
||||
@Override
|
||||
public String buildCommand(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) {
|
||||
String classPath = NodeProjectInfoModel.getClassPathLib(nodeProjectInfoModel);
|
||||
if (StrUtil.isBlank(classPath)) {
|
||||
return null;
|
||||
}
|
||||
// 拼接命令
|
||||
String jvm = javaCopyItem == null ? nodeProjectInfoModel.getJvm() : javaCopyItem.getJvm();
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
String mainClass = nodeProjectInfoModel.getMainClass();
|
||||
String args = javaCopyItem == null ? nodeProjectInfoModel.getArgs() : javaCopyItem.getArgs();
|
||||
return String.format("%s %s %s " +
|
||||
"%s %s %s >> %s &",
|
||||
getRunJavaPath(nodeProjectInfoModel, true),
|
||||
jvm, JvmUtil.getJpomPidTag(tag, nodeProjectInfoModel.allLib()),
|
||||
classPath, mainClass, args, nodeProjectInfoModel.getAbsoluteLog(javaCopyItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
|
||||
String result = super.stop(nodeProjectInfoModel, javaCopyItem);
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
// 查询状态,如果正在运行,则执行杀进程命令
|
||||
int pid = parsePid(result);
|
||||
if (pid > 0) {
|
||||
String kill = AbstractSystemCommander.getInstance().kill(FileUtil.file(nodeProjectInfoModel.allLib()), pid);
|
||||
loopCheckRun(nodeProjectInfoModel.getId(), false);
|
||||
result = status(tag) + StrUtil.SPACE + kill;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public String stop(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) throws Exception {
|
||||
Tuple tuple = super.stopBefore(nodeProjectInfoModel, javaCopyItem);
|
||||
String webHook = tuple.get(0);
|
||||
String result = tuple.get(1);
|
||||
String tag = javaCopyItem == null ? nodeProjectInfoModel.getId() : javaCopyItem.getTagId();
|
||||
// 查询状态,如果正在运行,则执行杀进程命令
|
||||
int pid = parsePid(result);
|
||||
if (pid > 0) {
|
||||
String kill = AbstractSystemCommander.getInstance().kill(FileUtil.file(nodeProjectInfoModel.allLib()), pid);
|
||||
loopCheckRun(nodeProjectInfoModel.getId(), false);
|
||||
result = status(tag) + StrUtil.SPACE + kill;
|
||||
}
|
||||
return StrUtil.format("{} {}", result, webHook);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetstatModel> listNetstat(int pId, boolean listening) {
|
||||
String cmd;
|
||||
if (listening) {
|
||||
cmd = "netstat -nao -p tcp | findstr \"LISTENING\" | findstr " + pId;
|
||||
} else {
|
||||
cmd = "netstat -nao -p tcp | findstr /V \"CLOSE_WAIT\" | findstr " + pId;
|
||||
}
|
||||
String result = CommandUtil.execSystemCommand(cmd);
|
||||
List<String> netList = StrSplitter.splitTrim(result, StrUtil.LF, true);
|
||||
if (netList == null || netList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
List<NetstatModel> array = new ArrayList<>();
|
||||
for (String str : netList) {
|
||||
List<String> list = StrSplitter.splitTrim(str, " ", true);
|
||||
if (list.size() < 5) {
|
||||
continue;
|
||||
}
|
||||
NetstatModel netstatModel = new NetstatModel();
|
||||
netstatModel.setProtocol(list.get(0));
|
||||
netstatModel.setLocal(list.get(1));
|
||||
netstatModel.setForeign(list.get(2));
|
||||
netstatModel.setStatus(list.get(3));
|
||||
netstatModel.setName(list.get(4));
|
||||
array.add(netstatModel);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@Override
|
||||
public List<NetstatModel> listNetstat(int pId, boolean listening) {
|
||||
String cmd;
|
||||
if (listening) {
|
||||
cmd = "netstat -nao -p tcp | findstr \"LISTENING\" | findstr " + pId;
|
||||
} else {
|
||||
cmd = "netstat -nao -p tcp | findstr /V \"CLOSE_WAIT\" | findstr " + pId;
|
||||
}
|
||||
String result = CommandUtil.execSystemCommand(cmd);
|
||||
List<String> netList = StrSplitter.splitTrim(result, StrUtil.LF, true);
|
||||
if (netList == null || netList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
List<NetstatModel> array = new ArrayList<>();
|
||||
for (String str : netList) {
|
||||
List<String> list = StrSplitter.splitTrim(str, " ", true);
|
||||
if (list.size() < 5) {
|
||||
continue;
|
||||
}
|
||||
NetstatModel netstatModel = new NetstatModel();
|
||||
netstatModel.setProtocol(list.get(0));
|
||||
netstatModel.setLocal(list.get(1));
|
||||
netstatModel.setForeign(list.get(2));
|
||||
netstatModel.setStatus(list.get(3));
|
||||
netstatModel.setName(list.get(4));
|
||||
array.add(netstatModel);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Code Technology Studio
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
//package io.jpom.socket.spring.handler;
|
||||
//
|
||||
//import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import io.jpom.JpomApplication;
|
||||
//import io.jpom.common.JpomManifest;
|
||||
//import io.jpom.model.AgentFileModel;
|
||||
//import io.jpom.model.WebSocketMessageModel;
|
||||
//import io.jpom.model.data.UploadFileModel;
|
||||
//import io.jpom.system.AgentConfigBean;
|
||||
//import org.springframework.web.socket.BinaryMessage;
|
||||
//import org.springframework.web.socket.TextMessage;
|
||||
//import org.springframework.web.socket.WebSocketSession;
|
||||
//import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
//
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * 节点升级websocket处理器
|
||||
// *
|
||||
// * @author lf
|
||||
// */
|
||||
//public class NodeUpdateHandler extends AbstractWebSocketHandler {
|
||||
// private static final Map<String, UploadFileModel> UPLOAD_FILE_INFO = new HashMap<>();
|
||||
//
|
||||
// @Override
|
||||
// public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||
// // 设置二进制消息的最大长度为1M
|
||||
// session.setBinaryMessageSizeLimit(1024 * 1024);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception {
|
||||
// UploadFileModel uploadFileModel = UPLOAD_FILE_INFO.get(session.getId());
|
||||
// uploadFileModel.save(message.getPayload().array());
|
||||
// // 更新进度
|
||||
// WebSocketMessageModel model = new WebSocketMessageModel("updateNode", uploadFileModel.getId());
|
||||
// model.setData(uploadFileModel);
|
||||
// session.sendMessage(new TextMessage(model.toString()));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 重启
|
||||
// *
|
||||
// * @param session
|
||||
// * @return
|
||||
// */
|
||||
// public String restart(WebSocketSession session) {
|
||||
// String result = "重启中";
|
||||
// try {
|
||||
// UploadFileModel uploadFile = UPLOAD_FILE_INFO.get(session.getId());
|
||||
// JpomManifest.releaseJar(uploadFile.getFilePath(), uploadFile.getVersion(), true);
|
||||
// JpomApplication.restart();
|
||||
// } catch (RuntimeException e) {
|
||||
// result = e.getMessage();
|
||||
// DefaultSystemLog.getLog().error("重启失败", e);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Code Technology Studio
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
//package io.jpom.socket.spring.interceptor;
|
||||
//
|
||||
//import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
//import io.jpom.system.AgentAuthorize;
|
||||
//import org.springframework.http.server.ServerHttpRequest;
|
||||
//import org.springframework.http.server.ServerHttpResponse;
|
||||
//import org.springframework.http.server.ServletServerHttpRequest;
|
||||
//import org.springframework.web.socket.WebSocketHandler;
|
||||
//import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * @author lf
|
||||
// */
|
||||
//public class NodeUpdateInterceptor implements HandshakeInterceptor {
|
||||
// @Override
|
||||
// public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler webSocketHandler, Map<String, Object> map) throws Exception {
|
||||
// if (request instanceof ServletServerHttpRequest) {
|
||||
// ServletServerHttpRequest serverHttpRequest = (ServletServerHttpRequest) request;
|
||||
// HttpServletRequest httpServletRequest = serverHttpRequest.getServletRequest();
|
||||
// // 判断用户
|
||||
// String name = httpServletRequest.getParameter("name");
|
||||
// String password = httpServletRequest.getParameter("password");
|
||||
//
|
||||
// AgentAuthorize authorize = AgentAuthorize.getInstance();
|
||||
// return authorize.getAgentName().equals(name) && authorize.getAgentPwd().equals(password);
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void afterHandshake(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse, WebSocketHandler webSocketHandler, Exception exception) {
|
||||
// if (exception != null) {
|
||||
// DefaultSystemLog.getLog().error("afterHandshake", exception);
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -20,26 +20,21 @@
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
//package io.jpom.socket.spring;
|
||||
//
|
||||
//import io.jpom.socket.spring.handler.NodeUpdateHandler;
|
||||
//import io.jpom.socket.spring.interceptor.NodeUpdateInterceptor;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
//import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
//import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||
//
|
||||
///**
|
||||
// * @author lf
|
||||
// */
|
||||
//@Configuration
|
||||
//@EnableWebSocket
|
||||
//public class WebSocketConfig implements WebSocketConfigurer {
|
||||
// private final NodeUpdateInterceptor nodeUpdateInterceptor = new NodeUpdateInterceptor();
|
||||
//
|
||||
// @Override
|
||||
// public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
// // 节点升级
|
||||
// registry.addHandler(new NodeUpdateHandler(), "/node_update").addInterceptors(nodeUpdateInterceptor);
|
||||
// }
|
||||
//}
|
||||
package cn;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import io.jpom.util.VersionUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/12/16
|
||||
*/
|
||||
public class TestVersions {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String version = VersionUtils.getVersion(HttpUtil.class, null);
|
||||
System.out.println(version);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user