mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 11:58:01 +08:00
fix 程序启动写入全局临时信息
fix 程序运行的 tmp 文件夹跟随项目目录 java.io.tmpdir
This commit is contained in:
parent
56d77f1aa3
commit
ed0b7f91c6
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,5 +1,17 @@
|
|||||||
# 🚀 版本日志
|
# 🚀 版本日志
|
||||||
|
|
||||||
|
## 2.10.8
|
||||||
|
|
||||||
|
### 🐞 解决BUG、优化功能
|
||||||
|
|
||||||
|
1. 【all】优化 程序运行的 tmp 文件夹跟随项目目录 `java.io.tmpdir`
|
||||||
|
|
||||||
|
### ❌ 不兼容功能
|
||||||
|
|
||||||
|
1. 【all】取消 程序启动写入全局临时信息
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
## 2.10.7 (2023-01-04)
|
## 2.10.7 (2023-01-04)
|
||||||
|
|
||||||
### 🐣 新增功能
|
### 🐣 新增功能
|
||||||
|
@ -38,6 +38,7 @@ if "%JAVA_HOME%"=="" (
|
|||||||
|
|
||||||
set PID_TAG="JPOM_AGENT_APPLICATION"
|
set PID_TAG="JPOM_AGENT_APPLICATION"
|
||||||
set conf_dir="%ENV_PATH%/../conf/"
|
set conf_dir="%ENV_PATH%/../conf/"
|
||||||
|
set tmpdir="%ENV_PATH%/../tmp/"
|
||||||
|
|
||||||
@REM see org.springframework.util.StringUtils.cleanPath
|
@REM see org.springframework.util.StringUtils.cleanPath
|
||||||
@REM set org.springframework.boot.context.config.StandardConfigDataLocationResolver.getResourceLocation
|
@REM set org.springframework.boot.context.config.StandardConfigDataLocationResolver.getResourceLocation
|
||||||
@ -56,7 +57,7 @@ set agent_log="%log_dir%\agent.log"
|
|||||||
set stdout_log="%log_dir%\stdout.log"
|
set stdout_log="%log_dir%\stdout.log"
|
||||||
|
|
||||||
set JAVA_MEM_OPTS= -Xms200m -Xmx600m -XX:PermSize=128m -XX:+UseG1GC
|
set JAVA_MEM_OPTS= -Xms200m -Xmx600m -XX:PermSize=128m -XX:+UseG1GC
|
||||||
set JAVA_OPTS_EXT= -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8
|
set JAVA_OPTS_EXT= -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Djava.io.tmpdir="%tmpdir%"
|
||||||
set APP_OPTS= -Djpom.application.tag="%PID_TAG%" -Dlogging.config="%logback_configurationFile%" -Dspring.config.location="%application_conf%"
|
set APP_OPTS= -Djpom.application.tag="%PID_TAG%" -Dlogging.config="%logback_configurationFile%" -Dspring.config.location="%application_conf%"
|
||||||
set JAVA_OPTS= %JAVA_MEM_OPTS% %JAVA_OPTS_EXT% %APP_OPTS%
|
set JAVA_OPTS= %JAVA_MEM_OPTS% %JAVA_OPTS_EXT% %APP_OPTS%
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ base=${bin_abs_path}/..
|
|||||||
conf_path="${base}/conf"
|
conf_path="${base}/conf"
|
||||||
Lib="${base}/lib/"
|
Lib="${base}/lib/"
|
||||||
LogPath="${base}/logs/"
|
LogPath="${base}/logs/"
|
||||||
|
tmpdir="${base}/tmp/"
|
||||||
Log="${LogPath}/stdout.log"
|
Log="${LogPath}/stdout.log"
|
||||||
logback_configurationFile="${conf_path}/logback.xml"
|
logback_configurationFile="${conf_path}/logback.xml"
|
||||||
application_conf="${conf_path}/application.yml"
|
application_conf="${conf_path}/application.yml"
|
||||||
@ -90,8 +91,9 @@ if [ -n "$Java64Str" ]; then
|
|||||||
else
|
else
|
||||||
JAVA_OPTS="-server ${USR_JVM_SIZE} -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m $JAVA_OPTS"
|
JAVA_OPTS="-server ${USR_JVM_SIZE} -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m $JAVA_OPTS"
|
||||||
fi
|
fi
|
||||||
JAVA_OPTS=" $JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
|
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
|
||||||
JAVA_OPTS="${JAVA_OPTS} -Dlogging.config=$logback_configurationFile -Dspring.config.location=$application_conf"
|
JAVA_OPTS="$JAVA_OPTS -Dlogging.config=$logback_configurationFile -Dspring.config.location=$application_conf"
|
||||||
|
JAVA_OPTS="$JAVA_OPTS -Djava.io.tmpdir=$tmpdir"
|
||||||
|
|
||||||
if [[ -z "${RUN_ARG}" ]]; then
|
if [[ -z "${RUN_ARG}" ]]; then
|
||||||
MAIN_ARGS="$*"
|
MAIN_ARGS="$*"
|
||||||
|
@ -29,6 +29,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import io.jpom.JpomApplication;
|
import io.jpom.JpomApplication;
|
||||||
|
import io.jpom.common.Const;
|
||||||
import io.jpom.common.ILoadEvent;
|
import io.jpom.common.ILoadEvent;
|
||||||
import io.jpom.model.system.AgentAutoUser;
|
import io.jpom.model.system.AgentAutoUser;
|
||||||
import io.jpom.util.JsonFileUtil;
|
import io.jpom.util.JsonFileUtil;
|
||||||
@ -39,6 +40,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* agent 端授权账号信息
|
* agent 端授权账号信息
|
||||||
*
|
*
|
||||||
@ -92,12 +95,12 @@ public class AgentAuthorize implements ILoadEvent {
|
|||||||
public boolean checkAuthorize(String authorize) {
|
public boolean checkAuthorize(String authorize) {
|
||||||
return StrUtil.equals(authorize, this.authorize);
|
return StrUtil.equals(authorize, this.authorize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查是否配置密码
|
* 检查是否配置密码
|
||||||
*/
|
*/
|
||||||
private void checkPwd() {
|
private void checkPwd() {
|
||||||
String path = configBean.getAgentAutoAuthorizeFile(configBean.getDataPath());
|
File path = FileUtil.file(configBean.getDataPath(), Const.AUTHORIZE);
|
||||||
if (StrUtil.isNotEmpty(agentPwd)) {
|
if (StrUtil.isNotEmpty(agentPwd)) {
|
||||||
// 有指定密码 清除旧密码信息
|
// 有指定密码 清除旧密码信息
|
||||||
FileUtil.del(path);
|
FileUtil.del(path);
|
||||||
|
@ -134,27 +134,7 @@ public class JpomApplication implements DisposableBean {
|
|||||||
FileUtil.del(scriptFile);
|
FileUtil.del(scriptFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前项目全局 运行信息文件路径
|
|
||||||
*
|
|
||||||
* @param type 程序类型
|
|
||||||
* @return file
|
|
||||||
*/
|
|
||||||
public File getApplicationJpomInfo(Type type) {
|
|
||||||
return FileUtil.file(SystemUtil.getUserInfo().getTempDir(), "jpom", type.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取 agent 端自动生成的授权文件路径
|
|
||||||
*
|
|
||||||
* @param dataPath 指定数据路径
|
|
||||||
* @return file
|
|
||||||
*/
|
|
||||||
public String getAgentAutoAuthorizeFile(String dataPath) {
|
|
||||||
return FileUtil.normalize(dataPath + StrUtil.SLASH + Const.AUTHORIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取临时文件存储路径
|
* 获取临时文件存储路径
|
||||||
*
|
*
|
||||||
|
@ -29,7 +29,6 @@ import cn.hutool.core.exceptions.ExceptionUtil;
|
|||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.net.NetUtil;
|
import cn.hutool.core.net.NetUtil;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
@ -97,21 +96,9 @@ public class JpomApplicationEvent implements ApplicationListener<ApplicationEven
|
|||||||
|
|
||||||
} else if (event instanceof ContextClosedEvent) {
|
} else if (event instanceof ContextClosedEvent) {
|
||||||
//
|
//
|
||||||
File appJpomFile = configBean.getApplicationJpomInfo(JpomApplication.getAppType());
|
|
||||||
FileUtil.del(appJpomFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeRunTempInfo() {
|
|
||||||
try {
|
|
||||||
// 写入Jpom 信息 、 写入全局信息
|
|
||||||
JpomManifest jpomManifest = JpomManifest.getInstance();
|
|
||||||
File appJpomFile = configBean.getApplicationJpomInfo(JpomApplication.getAppType());
|
|
||||||
FileUtil.writeString(jpomManifest.toString(), appJpomFile, CharsetUtil.CHARSET_UTF_8);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("写入全局运行信息失败:{}", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkPath() {
|
private void checkPath() {
|
||||||
String path = ExtConfigBean.getPath();
|
String path = ExtConfigBean.getPath();
|
||||||
@ -358,8 +345,6 @@ public class JpomApplicationEvent implements ApplicationListener<ApplicationEven
|
|||||||
this.checkDuplicateRun();
|
this.checkDuplicateRun();
|
||||||
// 开始异常加载
|
// 开始异常加载
|
||||||
this.statLoad();
|
this.statLoad();
|
||||||
// 写入全局运行信息
|
|
||||||
this.writeRunTempInfo();
|
|
||||||
// 提示成功消息
|
// 提示成功消息
|
||||||
this.success();
|
this.success();
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,16 @@ public class JsonFileUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存json 文件,同步
|
||||||
|
*
|
||||||
|
* @param path 路径
|
||||||
|
* @param json 新的json内容
|
||||||
|
*/
|
||||||
|
public static void saveJson(File path, Object json) {
|
||||||
|
saveJson(path.getAbsolutePath(), json);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> JSONObject arrayToObjById(JSONArray array) {
|
public static <T> JSONObject arrayToObjById(JSONArray array) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
array.forEach(o -> {
|
array.forEach(o -> {
|
||||||
|
@ -38,6 +38,7 @@ if "%JAVA_HOME%"=="" (
|
|||||||
|
|
||||||
set PID_TAG="JPOM_SERVER_APPLICATION"
|
set PID_TAG="JPOM_SERVER_APPLICATION"
|
||||||
set conf_dir="%ENV_PATH%/../conf/"
|
set conf_dir="%ENV_PATH%/../conf/"
|
||||||
|
set tmpdir="%ENV_PATH%/../tmp/"
|
||||||
|
|
||||||
@REM see org.springframework.util.StringUtils.cleanPath
|
@REM see org.springframework.util.StringUtils.cleanPath
|
||||||
@REM set org.springframework.boot.context.config.StandardConfigDataLocationResolver.getResourceLocation
|
@REM set org.springframework.boot.context.config.StandardConfigDataLocationResolver.getResourceLocation
|
||||||
@ -56,7 +57,7 @@ set server_log="%log_dir%\server.log"
|
|||||||
set stdout_log="%log_dir%\stdout.log"
|
set stdout_log="%log_dir%\stdout.log"
|
||||||
|
|
||||||
set JAVA_MEM_OPTS= -Xms1024m -Xmx2048m -XX:PermSize=128m -XX:+UseG1GC
|
set JAVA_MEM_OPTS= -Xms1024m -Xmx2048m -XX:PermSize=128m -XX:+UseG1GC
|
||||||
set JAVA_OPTS_EXT= -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8
|
set JAVA_OPTS_EXT= -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Djava.io.tmpdir="%tmpdir%"
|
||||||
set APP_OPTS= -Djpom.application.tag="%PID_TAG%" -Dlogging.config="%logback_configurationFile%" -Dspring.config.location="%application_conf%"
|
set APP_OPTS= -Djpom.application.tag="%PID_TAG%" -Dlogging.config="%logback_configurationFile%" -Dspring.config.location="%application_conf%"
|
||||||
set JAVA_OPTS= %JAVA_MEM_OPTS% %JAVA_OPTS_EXT% %APP_OPTS%
|
set JAVA_OPTS= %JAVA_MEM_OPTS% %JAVA_OPTS_EXT% %APP_OPTS%
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ base=$(absPath "$bin_abs_path/../")
|
|||||||
conf_path="${base}/conf"
|
conf_path="${base}/conf"
|
||||||
Lib="${base}/lib/"
|
Lib="${base}/lib/"
|
||||||
LogPath="${base}/logs/"
|
LogPath="${base}/logs/"
|
||||||
|
tmpdir="${base}/tmp/"
|
||||||
Log="${LogPath}/stdout.log"
|
Log="${LogPath}/stdout.log"
|
||||||
logback_configurationFile="${conf_path}/logback.xml"
|
logback_configurationFile="${conf_path}/logback.xml"
|
||||||
application_conf="${conf_path}/application.yml"
|
application_conf="${conf_path}/application.yml"
|
||||||
@ -114,8 +115,9 @@ if [ -n "$Java64Str" ]; then
|
|||||||
else
|
else
|
||||||
JAVA_OPTS="-server ${USR_JVM_SIZE} -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m $JAVA_OPTS"
|
JAVA_OPTS="-server ${USR_JVM_SIZE} -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m $JAVA_OPTS"
|
||||||
fi
|
fi
|
||||||
JAVA_OPTS=" $JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
|
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
|
||||||
JAVA_OPTS="${JAVA_OPTS} -Dlogging.config=$logback_configurationFile -Dspring.config.location=$application_conf"
|
JAVA_OPTS="$JAVA_OPTS -Dlogging.config=$logback_configurationFile -Dspring.config.location=$application_conf"
|
||||||
|
JAVA_OPTS="$JAVA_OPTS -Djava.io.tmpdir=$tmpdir"
|
||||||
|
|
||||||
MAIN_ARGS="$*"
|
MAIN_ARGS="$*"
|
||||||
|
|
||||||
|
@ -24,20 +24,12 @@ package io.jpom.system.init;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import io.jpom.JpomApplication;
|
import io.jpom.JpomApplication;
|
||||||
import io.jpom.common.ILoadEvent;
|
import io.jpom.common.ILoadEvent;
|
||||||
import io.jpom.common.JpomManifest;
|
|
||||||
import io.jpom.common.ServerConst;
|
import io.jpom.common.ServerConst;
|
||||||
import io.jpom.common.Type;
|
|
||||||
import io.jpom.model.data.NodeModel;
|
|
||||||
import io.jpom.model.system.AgentAutoUser;
|
|
||||||
import io.jpom.service.node.NodeService;
|
|
||||||
import io.jpom.util.JsonFileUtil;
|
import io.jpom.util.JsonFileUtil;
|
||||||
import io.jpom.util.JvmUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@ -54,16 +46,12 @@ import java.io.File;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class AutoImportLocalNode implements ILoadEvent {
|
public class AutoImportLocalNode implements ILoadEvent {
|
||||||
|
|
||||||
private final NodeService nodeService;
|
|
||||||
private final JpomApplication configBean;
|
private final JpomApplication configBean;
|
||||||
|
|
||||||
public AutoImportLocalNode(NodeService nodeService,
|
public AutoImportLocalNode(JpomApplication configBean) {
|
||||||
JpomApplication configBean) {
|
|
||||||
this.nodeService = nodeService;
|
|
||||||
this.configBean = configBean;
|
this.configBean = configBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void install() {
|
private void install() {
|
||||||
File file = FileUtil.file(configBean.getDataPath(), ServerConst.INSTALL);
|
File file = FileUtil.file(configBean.getDataPath(), ServerConst.INSTALL);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -77,60 +65,8 @@ public class AutoImportLocalNode implements ILoadEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void loadAgent() {
|
|
||||||
long count = nodeService.count();
|
|
||||||
if (count > 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log.info("当前服务端中没有任何节点尝试加载本机节点");
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
Integer mainClassPid = JvmUtil.findMainClassPid(Type.Agent.getApplicationClass());
|
|
||||||
if (mainClassPid == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
findPid(mainClassPid.toString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("自动添加本机节点错误", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void findPid(String pid) {
|
|
||||||
File file = configBean.getApplicationJpomInfo(Type.Agent);
|
|
||||||
if (!file.exists() || file.isDirectory()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 比较进程id
|
|
||||||
String json = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
|
|
||||||
JpomManifest jpomManifest = JSONObject.parseObject(json, JpomManifest.class);
|
|
||||||
if (!pid.equals(String.valueOf(jpomManifest.getPid()))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 判断自动授权文件是否存在
|
|
||||||
String path = configBean.getAgentAutoAuthorizeFile(jpomManifest.getDataPath());
|
|
||||||
if (!FileUtil.exist(path)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
json = FileUtil.readString(path, CharsetUtil.CHARSET_UTF_8);
|
|
||||||
AgentAutoUser autoUser = JSONObject.parseObject(json, AgentAutoUser.class);
|
|
||||||
// 判断授权信息
|
|
||||||
//
|
|
||||||
NodeModel nodeModel = new NodeModel();
|
|
||||||
nodeModel.setUrl(StrUtil.format("127.0.0.1:{}", jpomManifest.getPort()));
|
|
||||||
nodeModel.setName("本机");
|
|
||||||
//nodeModel.setProtocol("http");
|
|
||||||
//
|
|
||||||
nodeModel.setLoginPwd(autoUser.getAgentPwd());
|
|
||||||
nodeModel.setLoginName(autoUser.getAgentName());
|
|
||||||
//
|
|
||||||
nodeModel.setOpenStatus(1);
|
|
||||||
nodeService.insertNotFill(nodeModel);
|
|
||||||
log.info("Automatically add native node successfully:" + nodeModel.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet(ApplicationContext applicationContext) throws Exception {
|
public void afterPropertiesSet(ApplicationContext applicationContext) throws Exception {
|
||||||
this.install();
|
this.install();
|
||||||
this.loadAgent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user