查看项目实际执行的命令行

This commit is contained in:
bwcx_jzy 2019-07-19 16:52:45 +08:00
parent ba6174ed8d
commit 05a22b9315
9 changed files with 84 additions and 45 deletions

View File

@ -14,6 +14,7 @@
8. 【Server】layui 升级到2.5.4
9. 【Server】新增项目监控功能
10. 【Server】新增在线构建项目功能
11. 【Server】新增查看项目实际执行的命令行
### 解决BUG、优化功能

View File

@ -5,4 +5,5 @@
3. ssl 到期提醒、快捷续签
4. 自定义启动命令
5. 重构用户权限
6. 支持查看服务端和插件端的日志

View File

@ -7,6 +7,7 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.JarClassLoader;
import cn.hutool.core.text.StrSpliter;
import cn.hutool.core.thread.GlobalThreadPool;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.system.SystemUtil;
@ -81,6 +82,14 @@ public abstract class AbstractProjectCommander {
//---------------------------------------------------- 基本操作----start
/**
* 生成可以执行的命令
*
* @param projectInfoModel 项目
* @return null 是条件不足
*/
public abstract String buildCommand(ProjectInfoModel projectInfoModel);
/**
* 启动
*
@ -88,7 +97,21 @@ public abstract class AbstractProjectCommander {
* @return 结果
* @throws Exception 异常
*/
public abstract String start(ProjectInfoModel projectInfoModel) throws Exception;
public String start(ProjectInfoModel projectInfoModel) throws Exception {
String msg = checkStart(projectInfoModel);
if (msg != null) {
return msg;
}
String command = buildCommand(projectInfoModel);
if (command == null) {
throw new JpomRuntimeException("没有需要执行的命令");
}
// 执行命令
GlobalThreadPool.execute(() -> CommandUtil.execSystemCommand(command, FileUtil.file(projectInfoModel.getLib())));
//
loopCheckRun(projectInfoModel.getId(), true);
return status(projectInfoModel.getId());
}
/**
* 查询出指定端口信息
@ -111,7 +134,7 @@ public abstract class AbstractProjectCommander {
String token = projectInfoModel.getToken();
if (StrUtil.isNotEmpty(token)) {
try {
String body = HttpUtil.createGet(token).execute().body();
String body = HttpUtil.createGet(token).form("projectId", projectInfoModel.getId()).execute().body();
DefaultSystemLog.LOG().info(projectInfoModel.getName() + ":" + body);
} catch (Exception e) {
DefaultSystemLog.ERROR().error("WebHooks 调用错误", e);

View File

@ -1,8 +1,6 @@
package cn.keepbx.jpom.common.commander.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.StrSpliter;
import cn.hutool.core.thread.GlobalThreadPool;
import cn.hutool.core.util.StrUtil;
import cn.keepbx.jpom.common.commander.AbstractProjectCommander;
import cn.keepbx.jpom.model.data.ProjectInfoModel;
@ -20,28 +18,22 @@ import java.util.List;
public class LinuxProjectCommander extends AbstractProjectCommander {
@Override
public String start(ProjectInfoModel projectInfoModel) throws Exception {
String msg = checkStart(projectInfoModel);
if (msg != null) {
return msg;
public String buildCommand(ProjectInfoModel projectInfoModel) {
String path = ProjectInfoModel.getClassPathLib(projectInfoModel);
if (StrUtil.isBlank(path)) {
return null;
}
// 拼接命令
String command = String.format("nohup java %s %s -Dapplication=%s -Dbasedir=%s %s %s >> %s 2>&1 &",
return String.format("nohup java %s %s -Dapplication=%s -Dbasedir=%s %s %s >> %s 2>&1 &",
projectInfoModel.getJvm(),
ProjectInfoModel.getClassPathLib(projectInfoModel),
path,
projectInfoModel.getId(),
projectInfoModel.getAbsoluteLib(),
projectInfoModel.getMainClass(),
projectInfoModel.getArgs(),
projectInfoModel.getAbsoluteLog());
//
GlobalThreadPool.execute(() -> CommandUtil.execSystemCommand(command, FileUtil.file(projectInfoModel.getLib())));
// 检查是否执行完毕
loopCheckRun(projectInfoModel.getId(), true);
return status(projectInfoModel.getId());
}
@Override
public String stop(ProjectInfoModel projectInfoModel) throws Exception {
String result = super.stop(projectInfoModel);

View File

@ -1,8 +1,6 @@
package cn.keepbx.jpom.common.commander.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.StrSpliter;
import cn.hutool.core.thread.GlobalThreadPool;
import cn.hutool.core.util.StrUtil;
import cn.keepbx.jpom.common.commander.AbstractProjectCommander;
import cn.keepbx.jpom.model.data.ProjectInfoModel;
@ -20,26 +18,20 @@ import java.util.List;
public class WindowsProjectCommander extends AbstractProjectCommander {
@Override
public String start(ProjectInfoModel projectInfoModel) throws Exception {
String msg = checkStart(projectInfoModel);
if (msg != null) {
return msg;
public String buildCommand(ProjectInfoModel projectInfoModel) {
String classPath = ProjectInfoModel.getClassPathLib(projectInfoModel);
if (StrUtil.isBlank(classPath)) {
return null;
}
// 拼接命令
String jvm = projectInfoModel.getJvm();
String tag = projectInfoModel.getId();
String mainClass = projectInfoModel.getMainClass();
String args = projectInfoModel.getArgs();
String classPath = ProjectInfoModel.getClassPathLib(projectInfoModel);
String command = String.format("javaw %s %s -Dapplication=%s -Dbasedir=%s %s %s >> %s &",
return String.format("javaw %s %s -Dapplication=%s -Dbasedir=%s %s %s >> %s &",
jvm, classPath, tag,
projectInfoModel.getAbsoluteLib(), mainClass, args, projectInfoModel.getAbsoluteLog());
// 执行命令
GlobalThreadPool.execute(() -> CommandUtil.execSystemCommand(command, FileUtil.file(projectInfoModel.getLib())));
//
loopCheckRun(projectInfoModel.getId(), true);
return status(projectInfoModel.getId());
}
@Override

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.JsonMessage;
import cn.keepbx.jpom.common.BaseAgentController;
import cn.keepbx.jpom.common.commander.AbstractProjectCommander;
import cn.keepbx.jpom.model.data.ProjectInfoModel;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -34,7 +35,13 @@ public class ProjectListController extends BaseAgentController {
*/
@RequestMapping(value = "getProjectItem", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String getProjectItem(String id) {
return JsonMessage.getString(200, "", projectInfoService.getItem(id));
ProjectInfoModel projectInfoModel = projectInfoService.getItem(id);
if (projectInfoModel != null) {
// 返回实际执行的命令
String command = AbstractProjectCommander.getInstance().buildCommand(projectInfoModel);
projectInfoModel.setRunCommand(command);
}
return JsonMessage.getString(200, "", projectInfoModel);
}
/**

View File

@ -54,6 +54,18 @@ public class ProjectInfoModel extends BaseModel {
* 节点分发项目不允许在项目管理中编辑
*/
private boolean outGivingProject;
/**
* 实际运行的命令
*/
private String runCommand;
public String getRunCommand() {
return runCommand;
}
public void setRunCommand(String runCommand) {
this.runCommand = runCommand;
}
public boolean isOutGivingProject() {
return outGivingProject;

View File

@ -27,7 +27,7 @@
<div class="layui-input-block">
<input type="text" name="gitUrl" required lay-verify="required"
value="$!model.gitUrl"
placeholder="请输入构建名称"
placeholder="请输入仓库地址"
class="layui-input">
</div>
</div>
@ -75,7 +75,7 @@
<div class="layui-input-block">
<input type="text" name="resultDirFile" required lay-verify="required"
value="$!model.resultDirFile"
placeholder="构建产物目录"
placeholder="构建产物目录,相对路径"
class="layui-input">
</div>
</div>
@ -111,6 +111,7 @@
<label class="layui-form-label">分发后</label>
<div class="layui-input-block">
<input type="text" disabled readonly
placeholder="请选择分发项目"
value="#if($cOutAfterOpt)#foreach($coItem in $outAfterOpt)#if($cOutAfterOpt==$coItem.code)$coItem.desc#end#end#end"
class="layui-input">

View File

@ -132,16 +132,6 @@
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">WebHooks</label>
<div class="layui-input-block">
<input #if($item.outGivingProject)readonly#end type="text" name="token" placeholder="关闭程序时自动请求,非必填"
class="layui-input"
value="#if($item)$!item.token#end">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">Jvm参数</label>
@ -160,15 +150,35 @@
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">WebHooks</label>
<div class="layui-input-block">
<input #if($item.outGivingProject)readonly#end type="text" name="token" placeholder="关闭程序时自动请求,非必填GET请求"
class="layui-input"
value="#if($item)$!item.token#end">
</div>
</div>
</div>
#if($item.runCommand)
<div class="layui-form-item">
<label class="layui-form-label">运行命令</label>
<div class="layui-input-block">
<blockquote class="layui-elem-quote layui-quote-nm">
$item.runCommand
</blockquote>
</div>
</div>
#end
#if(!$item || $user.isProject($node.id,$!item.id))
<div class="layui-form-item" style="padding-left: 20%">
#if(!$item.outGivingProject)
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitProject"
id="project_submit">提交
</button>
#end
#if($item && !$item.outGivingProject)
<a class="layui-btn layui-btn-warm" data-id="$item.id" id="delete_project">删除</a>
#if($item)
<a class="layui-btn layui-btn-warm" data-id="$item.id" id="delete_project">删除</a>
#end
#end
</div>
#end