mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-30 02:48:17 +08:00
节点首页新增快速结束进程方式
This commit is contained in:
parent
d66bf1766f
commit
a9158eb781
@ -12,6 +12,7 @@
|
||||
6. 新增windows快速升级
|
||||
7. 【Server】layui升级到最新版,文件上传支持进度条
|
||||
8. 新增节点内存、cpu、硬盘使用情况采集报表(感谢@£天空之城~龙)
|
||||
9. 节点首页新增快速结束进程方式
|
||||
|
||||
### 解决BUG、优化功能
|
||||
|
||||
|
@ -6,6 +6,7 @@ import io.jpom.common.commander.impl.LinuxSystemCommander;
|
||||
import io.jpom.common.commander.impl.WindowsSystemCommander;
|
||||
import io.jpom.model.system.ProcessModel;
|
||||
import io.jpom.system.JpomRuntimeException;
|
||||
import io.jpom.util.CommandUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@ -100,4 +101,22 @@ public abstract class AbstractSystemCommander {
|
||||
* @return 结果
|
||||
*/
|
||||
public abstract String stopService(String serviceName);
|
||||
|
||||
/**
|
||||
* 构建kill 命令
|
||||
*
|
||||
* @param pid 进程编号
|
||||
* @return 结束进程命令
|
||||
*/
|
||||
public abstract String buildKill(int pid);
|
||||
|
||||
/**
|
||||
* kill
|
||||
*
|
||||
* @param pid 进程编号
|
||||
*/
|
||||
public String kill(File file, int pid) {
|
||||
String kill = buildKill(pid);
|
||||
return CommandUtil.execSystemCommand(kill, file);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.text.StrSpliter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
import io.jpom.common.commander.AbstractSystemCommander;
|
||||
import io.jpom.model.data.ProjectInfoModel;
|
||||
import io.jpom.model.system.NetstatModel;
|
||||
import io.jpom.util.CommandUtil;
|
||||
@ -39,11 +40,10 @@ public class LinuxProjectCommander extends AbstractProjectCommander {
|
||||
String result = super.stop(projectInfoModel);
|
||||
int pid = parsePid(result);
|
||||
if (pid > 0) {
|
||||
String cmd = String.format("kill %s", pid);
|
||||
CommandUtil.asyncExeLocalCommand(FileUtil.file(projectInfoModel.allLib()), cmd);
|
||||
AbstractSystemCommander.getInstance().kill(FileUtil.file(projectInfoModel.allLib()), pid);
|
||||
if (loopCheckRun(projectInfoModel.getId(), false)) {
|
||||
// 强制杀进程
|
||||
cmd = String.format("kill -9 %s", pid);
|
||||
String cmd = String.format("kill -9 %s", pid);
|
||||
CommandUtil.asyncExeLocalCommand(FileUtil.file(projectInfoModel.allLib()), cmd);
|
||||
}
|
||||
String tag = projectInfoModel.getId();
|
||||
|
@ -211,4 +211,9 @@ public class LinuxSystemCommander extends AbstractSystemCommander {
|
||||
String format = StrUtil.format("service {} stop", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildKill(int pid) {
|
||||
return String.format("kill %s", pid);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.text.StrSpliter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jpom.common.commander.AbstractProjectCommander;
|
||||
import io.jpom.common.commander.AbstractSystemCommander;
|
||||
import io.jpom.model.data.ProjectInfoModel;
|
||||
import io.jpom.model.system.NetstatModel;
|
||||
import io.jpom.util.CommandUtil;
|
||||
@ -43,8 +44,7 @@ public class WindowsProjectCommander extends AbstractProjectCommander {
|
||||
// 查询状态,如果正在运行,则执行杀进程命令
|
||||
int pid = parsePid(result);
|
||||
if (pid > 0) {
|
||||
String cmd = String.format("taskkill /F /PID %s", pid);
|
||||
CommandUtil.asyncExeLocalCommand(FileUtil.file(projectInfoModel.allLib()), cmd);
|
||||
AbstractSystemCommander.getInstance().kill(FileUtil.file(projectInfoModel.allLib()), pid);
|
||||
loopCheckRun(projectInfoModel.getId(), false);
|
||||
result = status(tag);
|
||||
}
|
||||
|
@ -173,4 +173,9 @@ public class WindowsSystemCommander extends AbstractSystemCommander {
|
||||
String format = StrUtil.format("net stop {}", serviceName);
|
||||
return CommandUtil.execSystemCommand(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildKill(int pid) {
|
||||
return String.format("taskkill /F /PID %s", pid);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.jpom.controller;
|
||||
|
||||
import cn.hutool.cache.impl.CacheObj;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.controller.base.AbstractController;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -73,8 +75,20 @@ public class WelcomeController extends AbstractController {
|
||||
public String getProcessList() {
|
||||
List<ProcessModel> array = AbstractSystemCommander.getInstance().getProcessList();
|
||||
if (array != null && !array.isEmpty()) {
|
||||
array.sort(Comparator.comparingInt(ProcessModel::getPid));
|
||||
return JsonMessage.getString(200, "", array);
|
||||
}
|
||||
return JsonMessage.getString(402, "没有获取到进程信息");
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "kill.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@ResponseBody
|
||||
public String kill(int pid) {
|
||||
String result = AbstractSystemCommander.getInstance().kill(null, pid);
|
||||
if (StrUtil.isEmpty(result)) {
|
||||
result = "成功kill";
|
||||
}
|
||||
return JsonMessage.getString(200, result);
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,9 @@ public class CommandUtil {
|
||||
List<String> commands = getCommand();
|
||||
commands.add(command);
|
||||
ProcessBuilder pb = new ProcessBuilder(commands);
|
||||
if (file != null) {
|
||||
pb.directory(file);
|
||||
}
|
||||
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
|
||||
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
pb.redirectInput(ProcessBuilder.Redirect.INHERIT);
|
||||
|
@ -18,6 +18,7 @@ public enum NodeUrl {
|
||||
GetDirectTop("/getDirectTop"),
|
||||
Status("/status"),
|
||||
exportTop("/exportTop"),
|
||||
Kill("/kill.json"),
|
||||
|
||||
ProcessList("/processList", -1),
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ import io.jpom.common.forward.NodeUrl;
|
||||
import io.jpom.model.BaseEnum;
|
||||
import io.jpom.model.Cycle;
|
||||
import io.jpom.model.data.NodeModel;
|
||||
import io.jpom.model.data.UserModel;
|
||||
import io.jpom.model.log.SystemMonitorLog;
|
||||
import io.jpom.service.dblog.DbSystemMonitorLogService;
|
||||
import io.jpom.util.StringUtil;
|
||||
@ -193,4 +194,14 @@ public class NodeWelcomeController extends BaseServerController {
|
||||
public String getProcessList() {
|
||||
return NodeForward.request(getNode(), getRequest(), NodeUrl.ProcessList).toString();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "kill.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@ResponseBody
|
||||
public String kill() {
|
||||
UserModel user = getUser();
|
||||
if (user.isSystemUser()) {
|
||||
return JsonMessage.getString(405, "没有权限");
|
||||
}
|
||||
return NodeForward.request(getNode(), getRequest(), NodeUrl.Kill).toString();
|
||||
}
|
||||
}
|
||||
|
@ -52,10 +52,14 @@
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script type="text/html" id="bar">
|
||||
<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="kill">关闭</a>
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var cycleTime = [[${cycleTime}]];
|
||||
var ws, myEcharts;
|
||||
var col = [{field: 'pid', title: '进程id', sort: true, width: '6%'},
|
||||
var col = [
|
||||
{field: 'pid', title: '进程id', sort: true, width: '6%'},
|
||||
{field: 'command', title: '进程名称'},
|
||||
{field: 'port', title: '端口', sort: true, width: '6%'},
|
||||
{field: 'user', title: '所有者', width: '8%', sort: true},
|
||||
@ -65,10 +69,12 @@
|
||||
{field: 'cpu', title: '占用CPU', width: '8%', sort: true},
|
||||
{field: 'mem', title: '物理内存', width: '8%', sort: true},
|
||||
{field: 'time', title: '时间总计', sort: true},
|
||||
{field: 'pr', title: '优先级', width: '6%', sort: true},
|
||||
// {field: 'pr', title: '优先级', width: '6%', sort: true},
|
||||
// {field: 'NI', title: 'nice值', width: '6%', sort: true},
|
||||
{field: 'virt', title: '虚拟内存', width: '8%', sort: true},
|
||||
{field: 'shr', title: '共享内存', width: '8%', sort: true}];
|
||||
{field: 'shr', title: '共享内存', width: '8%', sort: true},
|
||||
{field: 'op', title: '操作', align: 'center', toolbar: '#bar', fixed: 'right'}
|
||||
];
|
||||
var config = {
|
||||
id: 'tab_monitor',
|
||||
elem: '#tab_monitor',
|
||||
@ -83,6 +89,31 @@
|
||||
//
|
||||
tableRender(config);
|
||||
loadProcessList();
|
||||
//
|
||||
// 表格工具条事件
|
||||
table.on('tool(tab_monitor)', function (obj) {
|
||||
var data = obj.data;
|
||||
var event = obj.event;
|
||||
if ('kill' === event) {
|
||||
layer.confirm('确定要结束该进程吗?', {
|
||||
title: '系统提示'
|
||||
}, function (index) {
|
||||
layer.close(index);
|
||||
loadingAjax({
|
||||
url: './kill.json',
|
||||
data: {
|
||||
pid: data.pid
|
||||
},
|
||||
success: function (data) {
|
||||
layer.msg(data.msg);
|
||||
if (200 === data.code) {
|
||||
loadTop();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadTop() {
|
||||
|
Loading…
Reference in New Issue
Block a user