新版安装方式

This commit is contained in:
jiangzeyin 2019-01-16 13:58:29 +08:00
parent f27a451bcb
commit 2a87f2fef8
24 changed files with 466 additions and 271 deletions

View File

@ -54,11 +54,11 @@
1. 下载安装包 [https://gitee.com/jiangzeyin/jpom/attach_files](https://gitee.com/jiangzeyin/jpom/attach_files)
2. 上传到服务解压到根目录
3. 修改运行参数配置信息 [run.sh](/bin/run.sh)
4. 修改默认账号信息 [data/user.json](/bin/data/user.json)
5. 执行如下命令(记得给命令文件添加权限奥[*chmod /jpom/run.sh 777*]
4. 执行如下命令(记得给命令文件添加权限奥[*chmod /jpom/run.sh 777*]
```
/jpom/run.sh start
```
5. 修改默认账号信息 在项目运行路径中找到【data/user.json】文件修改[data/user.json](/src/main/resources/bin/data/user.json)
6. 配置端口访问域名或者指定端口访问如果是nginx推荐配置[/doc/jpom.conf](/doc/jpom.conf)
### 编译安装
@ -66,8 +66,7 @@
访问[Jpom](https://gitee.com/jiangzeyin/jpom)的码云主页,拉取最新完整代码:
1. 端口修改确认默认2122
2. 项目运行数据目录修改确认,如需修改请查看[/src/main/resources/application.yml](/src/main/resources/application.yml)(默认:/jpom/data/)数据路径存储用户信息和项目配置信息,基础格查看项目目录[/bin/data](/bin/data)
3. 项目运行命令目录修改确认,如需修改请查看[/src/main/resources/application.yml](/src/main/resources/application.yml)(默认:/jpom/command/)完整命令查看项目目录[/bin/command](/bin/command) 在部署是需要完整copy此目录到配置的命令目录中
2. 项目运行目录修改确认,如需修改请查看[/src/main/resources/application.yml](/src/main/resources/application.yml)(默认:/jpom/)数据路径存储用户信息、项目配置信息、运行命令,基础格查看项目目录[/src/main/resources/bin](/src/main/resources/bin)
4. 项目运行日志目录确认,如需修改请查看[/src/main/resources/logback-spring.xml](/src/main/resources/logback-spring.xml)(默认:/jpom/log/
5. 进入项目目录执行,然后在目录中查看 target/jpom-1.0-lib
```

View File

@ -8,7 +8,7 @@ Log=${Path}"run.log"
LogBack=${Path}"log/"
JVM="-server "
# 修改项目端口号 和 数据运行目录
ARGS="--server.port=2122 --jpom.data=/jpom/data/ --jpom.command=/jpom/command/"
ARGS="--server.port=2122 --jpom.path=/jpom/"
echo ${Tag}
RETVAL="0"

View File

@ -14,7 +14,7 @@
2. 在Jpom 配置对应项目的 CodePipeline 项目名称(记得结尾添加一个`_`奥)
![CodePipeline](./images/build_edit.png)
3. 配置阿里云oss 信息,在项目运行数据目录添加如[/bin/data/oss_dev.json](/bin/data/oss_dev.json),dev 是根据boot项目当前运行模式默认为dev,如项目运行模式为prod 则文件名应为【oss_prod.json】
3. 配置阿里云oss 信息,在项目运行数据目录添加配置信息如[/bin/data/oss_dev.json](/bin/data/oss_dev.json),dev 是根据boot项目当前运行模式默认为dev,如项目运行模式为prod 则文件名应为【oss_prod.json】,具体路径如【/jpom/data/oss_dev.json】
4. 在项目列表中操作点击构建按钮
![CodePipeline](./images/build_list.png)

View File

@ -9,8 +9,9 @@ import cn.jiangzeyin.common.PageUtil;
import cn.jiangzeyin.controller.BaseController;
import cn.jiangzeyin.controller.multipart.MultipartFileBuilder;
import cn.jiangzeyin.model.ProjectInfoModel;
import cn.jiangzeyin.service.manage.CommandService;
import cn.jiangzeyin.service.manage.ManageService;
import cn.jiangzeyin.system.ConfigBean;
import cn.jiangzeyin.system.ConfigException;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.MediaType;
@ -21,7 +22,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -35,8 +35,6 @@ public class FileControl extends BaseController {
@Resource
private ManageService manageService;
@Resource
private CommandService commandService;
/**
* 文件管理页面
@ -57,36 +55,36 @@ public class FileControl extends BaseController {
*/
@RequestMapping(value = "getRunBoot")
@ResponseBody
public String getRunBoot() {
File file = commandService.getCommandFile();
public String getRunBoot() throws ConfigException {
String file = ConfigBean.getInstance().getRunCommandPath();
String content = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
Map<String, String> map = new HashMap<>(1);
map.put("content", content);
return JsonMessage.getString(200, "success", map);
}
/**
* 修改启动文件
*
* @param content 内容
* @return json
*/
@RequestMapping(value = "saveRunBoot")
@ResponseBody
public String saveRunBoot(String content) {
File file = commandService.getCommandFile();
// 写入文件
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write(content.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
DefaultSystemLog.ERROR().error(e.getMessage(), e);
}
return JsonMessage.getString(200, "success");
}
// /**
// * 修改启动文件
// *
// * @param content 内容
// * @return json
// */
// @RequestMapping(value = "saveRunBoot")
// @ResponseBody
// public String saveRunBoot(String content) {
// File file = commandService.getCommandFile();
// // 写入文件
// try {
// FileOutputStream fos = new FileOutputStream(file);
// fos.write(content.getBytes());
// fos.flush();
// fos.close();
// } catch (IOException e) {
// e.printStackTrace();
// DefaultSystemLog.ERROR().error(e.getMessage(), e);
// }
// return JsonMessage.getString(200, "success");
// }
/**
* 列出目录下的文件

View File

@ -6,6 +6,8 @@ import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.controller.BaseController;
import cn.jiangzeyin.model.ProjectInfoModel;
import cn.jiangzeyin.service.manage.CommandService;
import cn.jiangzeyin.system.ConfigBean;
import cn.jiangzeyin.system.ConfigException;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
@ -36,7 +38,7 @@ public class InternalController extends BaseController {
* 获取内存信息
*/
@RequestMapping(value = "internal", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public String getInternal(String tag) {
public String getInternal(String tag) throws ConfigException {
ProjectInfoModel projectInfoModel = new ProjectInfoModel();
projectInfoModel.setId(tag);
String pid = commandService.execCommand(CommandService.CommandOp.pid, projectInfoModel, null);
@ -62,9 +64,9 @@ public class InternalController extends BaseController {
String pid = commandService.execCommand(CommandService.CommandOp.pid, projectInfoModel, null).trim();
pid = pid.replace("\n", "");
// String fileName = "java_cpu" + RandomUtil.randomNumbers(5) + ".txt";
String fileName = commandService.getTempPathName() + "/" + tag + "_java_cpu.txt";
String fileName = ConfigBean.getInstance().getTempPathName() + "/" + tag + "_java_cpu.txt";
fileName = FileUtil.normalize(fileName);
String commandPath = commandService.getCpuCommandPath();
String commandPath = ConfigBean.getInstance().getCpuCommandPath();
String command = String.format("%s %s %s %s", commandPath, pid, 300, fileName);
commandService.execCommand(command);
downLoad(getResponse(), fileName);
@ -80,9 +82,9 @@ public class InternalController extends BaseController {
ProjectInfoModel projectInfoModel = new ProjectInfoModel();
projectInfoModel.setId(tag);
String pid = commandService.execCommand(CommandService.CommandOp.pid, projectInfoModel, null).trim();
String fileName = commandService.getTempPathName() + "/" + tag + "_java_ram.txt";
String fileName = ConfigBean.getInstance().getTempPathName() + "/" + tag + "_java_ram.txt";
fileName = FileUtil.normalize(fileName);
String commandPath = commandService.getRamCommandPath();
String commandPath = ConfigBean.getInstance().getRamCommandPath();
String command = String.format("%s %s %s", commandPath, pid, fileName);
commandService.execCommand(command);
downLoad(getResponse(), fileName);

View File

@ -0,0 +1,46 @@
package cn.jiangzeyin.model;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONObject;
/**
* @author jiangzeyin
* @date 2019/1/16
*/
public class UserModel {
private String id;
private String name;
private String password;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserMd5Key() {
return SecureUtil.md5(String.format("%s:%s", id, password));
}
public JSONObject toJson() {
return (JSONObject) JSONObject.toJSON(this);
}
}

View File

@ -0,0 +1,117 @@
package cn.jiangzeyin.service;
import cn.jiangzeyin.system.ConfigBean;
import cn.jiangzeyin.util.JsonUtil;
import com.alibaba.fastjson.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* @author jiangzeyin
* @date 2019/1/16
*/
public class BaseDataService extends BaseService {
/**
* 获取数据文件的路径如果文件不存在则创建一个
*
* @param filename 文件名
* @return
* @throws IOException
*/
private String getDataFilePath(String filename) throws IOException {
File file = new File(ConfigBean.getInstance().getDataPath(), filename);
if (!file.exists()) {
throw new FileNotFoundException(file.getPath() + " 文件不存在!");
}
return file.getPath();
}
/**
* 保存json对象
*
* @param filename 文件名
* @param json json数据
* @throws Exception
*/
protected void saveJson(String filename, JSONObject json) throws Exception {
String key = json.getString("id");
// 读取文件如果存在记录则抛出异常
JSONObject allData = getJsonObject(filename);
JSONObject data = allData.getJSONObject(key);
// 判断是否存在数据
if (null != data && 0 < data.keySet().size()) {
throw new Exception("项目名称已存在!");
} else {
allData.put(key, json);
JsonUtil.saveJson(getDataFilePath(filename), allData);
}
}
/**
* 修改json对象
*
* @param filename 文件名
* @param json json数据
*/
protected void updateJson(String filename, JSONObject json) throws Exception {
String key = json.getString("id");
// 读取文件如果不存在记录则抛出异常
JSONObject allData = getJsonObject(filename);
JSONObject data = allData.getJSONObject(key);
// 判断是否存在数据
if (null == data || 0 == data.keySet().size()) {
throw new Exception("数据不存在");
} else {
allData.put(key, json);
JsonUtil.saveJson(getDataFilePath(filename), allData);
}
}
/**
* 删除json对象
*
* @param filename
* @param key
* @throws Exception
*/
protected void deleteJson(String filename, String key) throws Exception {
// 读取文件如果存在记录则抛出异常
JSONObject allData = getJsonObject(filename);
JSONObject data = allData.getJSONObject(key);
// 判断是否存在数据
if (JsonUtil.jsonIsEmpty(data)) {
throw new Exception("项目名称存不在!");
} else {
allData.remove(key);
JsonUtil.saveJson(getDataFilePath(filename), allData);
}
}
/**
* 根据主键读取json对象
*
* @param filename 文件名
* @param key 主键
* @return json
* @throws IOException io
*/
protected JSONObject getJsonObject(String filename, String key) throws IOException {
JSONObject jsonData = getJsonObject(filename);
return jsonData.getJSONObject(key);
}
/**
* 读取整个json文件
*
* @param filename 文件名
* @return json
* @throws IOException io
*/
protected JSONObject getJsonObject(String filename) throws IOException {
return (JSONObject) JsonUtil.readJson(getDataFilePath(filename));
}
}

View File

@ -1,151 +1,8 @@
package cn.jiangzeyin.service;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.jiangzeyin.controller.BaseController;
import cn.jiangzeyin.util.JsonUtil;
import com.alibaba.fastjson.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* @author jiangzeyin
*/
public abstract class BaseService {
/**
* 获取数据的路径如果没有这个路径则创建一个
*
* @return file
*/
protected File getDataPath() throws IOException {
String path = SpringUtil.getEnvironment().getProperty("jpom.data");
File file = new File(path);
if (!file.exists() && !file.mkdirs()) {
throw new IOException(path);
}
return file;
}
public String getTempPathName() throws IOException {
File file = getTempPath();
return FileUtil.normalize(file.getPath());
}
protected File getTempPath() throws IOException {
File file = getDataPath();
String userName = BaseController.getUserName();
if (StrUtil.isEmpty(userName)) {
throw new RuntimeException("没有登录");
}
file = new File(file.getPath() + "/temp/", userName);
FileUtil.mkdir(file);
return file;
}
/**
* 获取数据文件的路径如果文件不存在则创建一个
*
* @param filename 文件名
* @return
* @throws IOException
*/
private String getDataFilePath(String filename) throws IOException {
File file = new File(getDataPath(), filename);
if (!file.exists()) {
throw new FileNotFoundException(file.getPath() + " 文件不存在!");
}
return file.getPath();
}
/**
* 保存json对象
*
* @param filename 文件名
* @param json json数据
* @throws Exception
*/
protected void saveJson(String filename, JSONObject json) throws Exception {
String key = json.getString("id");
// 读取文件如果存在记录则抛出异常
JSONObject allData = getJsonObject(filename);
JSONObject data = allData.getJSONObject(key);
// 判断是否存在数据
if (null != data && 0 < data.keySet().size()) {
throw new Exception("项目名称已存在!");
} else {
allData.put(key, json);
JsonUtil.saveJson(getDataFilePath(filename), allData);
}
}
/**
* 修改json对象
*
* @param filename 文件名
* @param json json数据
*/
protected void updateJson(String filename, JSONObject json) throws Exception {
String key = json.getString("id");
// 读取文件如果不存在记录则抛出异常
JSONObject allData = getJsonObject(filename);
JSONObject data = allData.getJSONObject(key);
// 判断是否存在数据
if (null == data || 0 == data.keySet().size()) {
throw new Exception("数据不存在");
} else {
allData.put(key, json);
JsonUtil.saveJson(getDataFilePath(filename), allData);
}
}
/**
* 删除json对象
*
* @param filename
* @param key
* @throws Exception
*/
protected void deleteJson(String filename, String key) throws Exception {
// 读取文件如果存在记录则抛出异常
JSONObject allData = getJsonObject(filename);
JSONObject data = allData.getJSONObject(key);
// 判断是否存在数据
if (JsonUtil.jsonIsEmpty(data)) {
throw new Exception("项目名称存不在!");
} else {
allData.remove(key);
JsonUtil.saveJson(getDataFilePath(filename), allData);
}
}
/**
* 根据主键读取json对象
*
* @param filename 文件名
* @param key 主键
* @return json
* @throws IOException io
*/
protected JSONObject getJsonObject(String filename, String key) throws IOException {
JSONObject jsonData = getJsonObject(filename);
return jsonData.getJSONObject(key);
}
/**
* 读取整个json文件
*
* @param filename 文件名
* @return json
* @throws IOException io
*/
protected JSONObject getJsonObject(String filename) throws IOException {
return (JSONObject) JsonUtil.readJson(getDataFilePath(filename));
}
}

View File

@ -1,9 +1,9 @@
package cn.jiangzeyin.service;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.model.UserModel;
import cn.jiangzeyin.system.ConfigBean;
import cn.jiangzeyin.util.JsonUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -17,9 +17,9 @@ import java.util.Set;
* @author Administrator
*/
@Service
public class UserService extends BaseService {
public class UserService extends BaseDataService {
private static final String FILENAME = "user.json";
private static final String FILENAME = ConfigBean.USER;
/**
* 用户登录
@ -33,7 +33,8 @@ public class UserService extends BaseService {
if (JsonUtil.jsonIsEmpty(userInfo)) {
return false;
}
return pwd.equals(userInfo.getString("password"));
UserModel userModel = userInfo.toJavaObject(UserModel.class);
return pwd.equals(userModel.getPassword());
}
@ -44,9 +45,8 @@ public class UserService extends BaseService {
}
for (String strKey : jsonData.keySet()) {
JSONObject jsonUser = jsonData.getJSONObject(strKey);
String id = jsonUser.getString("id");
String pwd = jsonUser.getString("password");
String strUsermd5 = SecureUtil.md5(String.format("%s:%s", id, pwd));
UserModel userModel = jsonUser.toJavaObject(UserModel.class);
String strUsermd5 = userModel.getUserMd5Key();
if (strUsermd5.equals(userMd5)) {
return true;
}
@ -121,7 +121,7 @@ public class UserService extends BaseService {
deleteJson(FILENAME, id);
return true;
} catch (Exception e) {
DefaultSystemLog.LOG().error(e.getMessage(), e);
DefaultSystemLog.ERROR().error(e.getMessage(), e);
}
return false;
}
@ -131,12 +131,11 @@ public class UserService extends BaseService {
*/
public boolean addUser(String id, String name, String password, String role) {
try {
JSONObject object = new JSONObject();
object.put("id", id);
object.put("name", name);
object.put("password", password);
object.put("role", role);
saveJson(FILENAME, object);
UserModel userModel = new UserModel();
userModel.setName(name);
userModel.setId(id);
userModel.setPassword(password);
saveJson(FILENAME, userModel.toJson());
return true;
} catch (Exception e) {
DefaultSystemLog.LOG().error(e.getMessage(), e);
@ -165,7 +164,7 @@ public class UserService extends BaseService {
updateJson(FILENAME, object);
return true;
} catch (Exception e) {
DefaultSystemLog.LOG().error(e.getMessage(), e);
DefaultSystemLog.ERROR().error(e.getMessage(), e);
}
return false;
}

View File

@ -3,19 +3,18 @@ package cn.jiangzeyin.service.manage;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.jiangzeyin.model.ProjectInfoModel;
import cn.jiangzeyin.service.BaseService;
import cn.jiangzeyin.socket.LogWebSocketHandle;
import cn.jiangzeyin.socket.SocketSession;
import cn.jiangzeyin.socket.TailLogThread;
import cn.jiangzeyin.system.ConfigBean;
import cn.jiangzeyin.system.ConfigException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.websocket.Session;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -59,46 +58,17 @@ public class CommandService extends BaseService {
top
}
public File getCommandFile() {
File file = new File(getRunCommandPath());
if (!file.exists()) {
throw new RuntimeException("启动文件不存在");
}
return file;
}
private String getRunCommandPath() {
String command = getCommandPath();
return command + "/run_boot.sh";
// return command;
}
//
// public File getCommandFile() {
// File file = new File(getRunCommandPath());
// if (!file.exists()) {
// throw new RuntimeException("启动文件不存在");
// }
// return file;
// }
private String getCommandPath() {
String command = SpringUtil.getEnvironment().getProperty("jpom.command");
if (StrUtil.isEmpty(command)) {
throw new RuntimeException("请配置命令文件");
}
return command;
}
public String getCpuCommandPath() {
String command = getCommandPath();
return command + "/java_cpu.sh";
// return command;
}
public String getRamCommandPath() {
String command = getCommandPath();
return command + "/java_ram.sh";
// return command;
}
public String execCommand(CommandOp commandOp, ProjectInfoModel projectInfoModel) {
public String execCommand(CommandOp commandOp, ProjectInfoModel projectInfoModel) throws ConfigException {
return execCommand(commandOp, projectInfoModel, null);
}
@ -108,10 +78,10 @@ public class CommandService extends BaseService {
* @param commandOp 执行的操作
* @param projectInfoModel 项目信息
*/
public String execCommand(CommandOp commandOp, ProjectInfoModel projectInfoModel, Evt evt) {
public String execCommand(CommandOp commandOp, ProjectInfoModel projectInfoModel, Evt evt) throws ConfigException {
String result;
CommandService commandService = SpringUtil.getBean(CommandService.class);
String commandPath = commandService.getRunCommandPath();
String commandPath = ConfigBean.getInstance().getRunCommandPath();
String tag = null, log = null;
// 项目启动信息
if (projectInfoModel != null) {

View File

@ -3,7 +3,8 @@ package cn.jiangzeyin.service.manage;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.model.ProjectInfoModel;
import cn.jiangzeyin.service.BaseService;
import cn.jiangzeyin.service.BaseDataService;
import cn.jiangzeyin.system.ConfigBean;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;
@ -14,9 +15,9 @@ import java.util.Set;
* @author jiangzeyin
*/
@Service
public class ManageService extends BaseService {
public class ManageService extends BaseDataService {
private static final String FILENAME = "project.json";
private static final String FILENAME = ConfigBean.PROJECT;
/**
* 查询所有项目信息

View File

@ -2,10 +2,9 @@ package cn.jiangzeyin.service.oss;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.jiangzeyin.service.BaseService;
import com.alibaba.fastjson.JSON;
import cn.jiangzeyin.service.BaseDataService;
import cn.jiangzeyin.system.ConfigBean;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
@ -28,10 +27,11 @@ import java.util.concurrent.TimeUnit;
* @date 2018/9/28
*/
@Service
public class OssManagerService extends BaseService {
public class OssManagerService extends BaseDataService {
public File download(String key) throws IOException {
File file = getTempPath();
File file = ConfigBean.getInstance().getTempPath();
//getTempPath();
file = new File(file, key);
OSSClient ossClient = getOSSClient();
// 下载OSS文件到本地文件如果指定的本地文件存在会覆盖不存在则新建
@ -97,13 +97,9 @@ public class OssManagerService extends BaseService {
private JSONObject getConfig() throws IOException {
String active = SpringUtil.getEnvironment().getProperty("spring.profiles.active");
File file = getDataPath();
file = new File(file, "oss_" + active + ".json");
if (!file.exists()) {
throw new IllegalArgumentException("请配置阿里云oss:" + file.getPath());
}
String json = FileUtil.readString(file, CharsetUtil.UTF_8);
return JSON.parseObject(json);
return getJsonObject("oss_" + active + ".json");
// String json = FileUtil.readString(file, CharsetUtil.UTF_8);
// return JSON.parseObject(json);
}
private String getBucketName() throws IOException {

View File

@ -5,6 +5,7 @@ import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.jiangzeyin.service.manage.CommandService;
import cn.jiangzeyin.socket.SocketSession;
import cn.jiangzeyin.system.ConfigException;
import javax.websocket.Session;
import java.io.IOException;
@ -43,7 +44,12 @@ public class TopManager {
CronUtil.remove(CRON_ID);
CronUtil.setMatchSecond(true);
CronUtil.schedule(CRON_ID, "0/5 * * * * ?", () -> {
String result = commandService.execCommand(CommandService.CommandOp.top, null, null);
String result = null;
try {
result = commandService.execCommand(CommandService.CommandOp.top, null, null);
} catch (ConfigException e) {
e.printStackTrace();
}
send(result);
});
CronUtil.restart();

View File

@ -0,0 +1,101 @@
package cn.jiangzeyin.system;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.jiangzeyin.controller.BaseController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.io.File;
/**
* @author jiangzeyin
* @date 2019/1/16
*/
@Configuration
public class ConfigBean {
private static final String COMMAND = "command";
private static final String DATA = "data";
private static ConfigBean configBean;
public static final String RUN_SH = "/run_boot.sh";
public static final String CPU_SH = "/java_cpu.sh";
public static final String RAM_SH = "/java_ram.sh";
public static final String USER = "user.json";
public static final String PROJECT = "project.json";
public static ConfigBean getInstance() {
if (configBean == null) {
synchronized (ConfigBean.class) {
if (configBean == null) {
configBean = SpringUtil.getBean(ConfigBean.class);
}
}
}
return configBean;
}
@Value("${jpom.path}")
private String path;
private String getPath() {
if (StrUtil.isEmpty(path)) {
throw new RuntimeException("请配运行路径属性【jpom.path】");
}
return path;
}
private String getCommandPath() {
String commandPath = FileUtil.normalize(getPath() + "/" + COMMAND);
FileUtil.mkdir(commandPath);
return commandPath;
}
public String getDataPath() {
String dataPath = FileUtil.normalize(getPath() + "/" + DATA);
FileUtil.mkdir(dataPath);
return dataPath;
}
public String getTempPathName() {
File file = getTempPath();
return FileUtil.normalize(file.getPath());
}
public File getTempPath() {
File file = new File(getDataPath());
String userName = BaseController.getUserName();
if (StrUtil.isEmpty(userName)) {
throw new RuntimeException("没有登录");
}
file = new File(file.getPath() + "/temp/", userName);
FileUtil.mkdir(file);
return file;
}
private String getCommandPath(String item) throws ConfigException {
String command = getCommandPath();
String runSh = FileUtil.normalize(command + item);
if (!FileUtil.exist(runSh)) {
throw new ConfigException(item + " 文件不存在:" + runSh, runSh);
}
return runSh;
}
public String getRunCommandPath() throws ConfigException {
return getCommandPath(RUN_SH);
}
public String getCpuCommandPath() throws ConfigException {
return getCommandPath(CPU_SH);
}
public String getRamCommandPath() throws ConfigException {
return getCommandPath(RAM_SH);
}
}

View File

@ -0,0 +1,20 @@
package cn.jiangzeyin.system;
import java.io.IOException;
/**
* @author jiangzeyin
* @date 2019/1/16
*/
public class ConfigException extends IOException {
private String path;
public String getPath() {
return path;
}
public ConfigException(String message, String path) {
super(message);
this.path = path;
}
}

View File

@ -0,0 +1,81 @@
package cn.jiangzeyin.system.init;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.PreLoadClass;
import cn.jiangzeyin.common.PreLoadMethod;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.jiangzeyin.service.manage.CommandService;
import cn.jiangzeyin.system.ConfigBean;
import cn.jiangzeyin.system.ConfigException;
import java.io.File;
import java.net.URL;
/**
* 检查运行命令
*
* @author jiangzeyin
* @date 2019/1/16
*/
@PreLoadClass
public class CheckRunCommand {
/**
* 检查命令文件
*/
@PreLoadMethod
private static void checkSh() {
try {
ConfigBean.getInstance().getRunCommandPath();
} catch (ConfigException e) {
DefaultSystemLog.LOG().info("创建默认文件:" + e.getPath());
addCommandFile(ConfigBean.RUN_SH, e.getPath());
}
try {
ConfigBean.getInstance().getRamCommandPath();
} catch (ConfigException e) {
DefaultSystemLog.LOG().info("创建默认文件:" + e.getPath());
addCommandFile(ConfigBean.RAM_SH, e.getPath());
}
try {
ConfigBean.getInstance().getCpuCommandPath();
} catch (ConfigException e) {
DefaultSystemLog.LOG().info("创建默认文件:" + e.getPath());
addCommandFile(ConfigBean.CPU_SH, e.getPath());
}
}
@PreLoadMethod
private static void checkData() {
File file = new File(ConfigBean.getInstance().getDataPath(), ConfigBean.USER);
if (!file.exists()) {
DefaultSystemLog.LOG().info("创建默认文件:" + file.getPath());
addDataFile(ConfigBean.USER, file.getPath());
}
file = new File(ConfigBean.getInstance().getDataPath(), ConfigBean.PROJECT);
if (!file.exists()) {
DefaultSystemLog.LOG().info("创建默认文件:" + file.getPath());
addDataFile(ConfigBean.PROJECT, file.getPath());
}
}
private static void addDataFile(String name, String file) {
URL url = ResourceUtil.getResource("bin/data/" + name);
String content = FileUtil.readString(url, CharsetUtil.UTF_8);
FileUtil.writeString(content, file, CharsetUtil.UTF_8);
}
private static void addCommandFile(String command, String file) {
URL url = ResourceUtil.getResource("bin/command" + command);
String content = FileUtil.readString(url, CharsetUtil.UTF_8);
FileUtil.writeString(content, file, CharsetUtil.UTF_8);
// 添加文件权限
CommandService commandService = SpringUtil.getBean(CommandService.class);
String runCommand = "chmod 777 " + file;
commandService.execCommand(runCommand);
}
}

View File

@ -1,11 +1,14 @@
package cn.jiangzeyin.util;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.File;
/**
* @author jiangzeyin
* date 2017/5/15
@ -33,8 +36,12 @@ public class JsonUtil {
}
public static Object readJson(String path) {
File file = new File(path);
if (!file.exists()) {
throw new RuntimeException("没有找到对应配置文件:" + path);
}
synchronized (JsonUtil.class) {
String json = FileUtil.readString(path, "UTF-8");
String json = FileUtil.readString(file, CharsetUtil.UTF_8);
if (StrUtil.isEmpty(json)) {
return JSONObject.parseObject("{}");
}

View File

@ -1,16 +1,10 @@
{
"properties": [
{
"name": "jpom.data",
"name": "jpom.path",
"type": "java.lang.String",
"description": "jpom 项目运行数据存储文件路径",
"defaultValue": ""
},
{
"name": "jpom.command",
"type": "java.lang.String",
"description": "jpom 项目运行控制shell 命令文件存储路径",
"defaultValue": ""
"description": "jpom 项目运行路径",
"defaultValue": "/jpom/"
}
]
}

View File

@ -24,11 +24,12 @@ banner:
msg: jpom 管理系统启动中
#boot online \u914D\u7F6E
jpom:
data: /jpom/data/
command: /jpom/command/
path: /jpom/
# \u9759\u6001\u8D44\u6E90
interceptor:
resourceHandler: /static/**
resourceLocation: classpath:/static/
tomcat:
sessionTimeOut: 18000
preload:
packageName: cn.jiangzeyin.system.init

View File

View File

@ -1,6 +1,6 @@
{
"admin": {
"password": "test",
"password": "adminadmin",
"role": true,
"name": "admin",
"id": "admin"