use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class CheckAuthorize method repairScriptPath.
/**
* 恢复脚本模板路径
*/
@PreLoadMethod
private static void repairScriptPath() {
if (!JpomManifest.getInstance().isDebug()) {
if (StrUtil.compareVersion(JpomManifest.getInstance().getVersion(), "2.4.2") < 0) {
return;
}
}
File oldDir = FileUtil.file(ExtConfigBean.getInstance().getPath(), ConfigBean.SCRIPT_DIRECTORY);
if (!oldDir.exists()) {
return;
}
File newDir = FileUtil.file(ConfigBean.getInstance().getDataPath(), ConfigBean.SCRIPT_DIRECTORY);
FileUtil.move(oldDir, newDir, true);
}
use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class CheckAuthorizeToken method check.
@PreLoadMethod
private static void check() {
String authorizeToken = ServerExtConfigBean.getInstance().getAuthorizeToken();
if (StrUtil.isEmpty(authorizeToken)) {
return;
}
if (authorizeToken.length() < 6) {
DefaultSystemLog.getLog().error("配置的授权token长度小于六位不生效", new JpomRuntimeException("配置的授权token长度小于六位不生效"));
System.exit(-1);
}
int strength = CheckPassword.checkPasswordStrength(authorizeToken);
if (strength != 2) {
DefaultSystemLog.getLog().error("配置的授权token 需要包含数字,字母,符号的组合", new JpomRuntimeException("配置的授权token 需要包含数字,字母,符号的组合"));
System.exit(-1);
}
}
use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class InitDb method init.
@PreLoadMethod(value = Integer.MIN_VALUE)
private static void init() {
//
DbConfig instance = DbConfig.getInstance();
ServerExtConfigBean serverExtConfigBean = ServerExtConfigBean.getInstance();
DbExtConfig dbExtConfig = SpringUtil.getBean(DbExtConfig.class);
//
Setting setting = new Setting();
String dbUrl = instance.getDbUrl();
setting.set("url", dbUrl);
setting.set("user", dbExtConfig.getUserName());
setting.set("pass", dbExtConfig.getUserPwd());
// 配置连接池大小
setting.set("maxActive", dbExtConfig.getMaxActive() + "");
setting.set("initialSize", dbExtConfig.getInitialSize() + "");
setting.set("maxWait", dbExtConfig.getMaxWait() + "");
setting.set("minIdle", dbExtConfig.getMinIdle() + "");
// 调试模式显示sql 信息
if (dbExtConfig.getShowSql()) {
setting.set(SqlLog.KEY_SHOW_SQL, "true");
/*
@author Hotstrip
sql log only show when it's needed,
if you want to check init sql,
set the [sqlLevel] from [DEBUG] to [INFO]
*/
setting.set(SqlLog.KEY_SQL_LEVEL, "DEBUG");
setting.set(SqlLog.KEY_SHOW_PARAMS, "true");
}
Console.log("start load h2 db");
String sqlFileNow = StrUtil.EMPTY;
try {
// 创建连接
DSFactory dsFactory = DSFactory.create(setting);
// 先执行恢复数据
instance.executeRecoverDbSql(dsFactory);
/*
@author Hotstrip
add another sql init file, if there are more sql file,
please add it with same way
*/
PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = pathMatchingResourcePatternResolver.getResources("classpath:/sql/*.sql");
// 加载 sql 变更记录,避免重复执行
Set<String> executeSqlLog = instance.loadExecuteSqlLog();
// 过滤 temp sql
List<Resource> resourcesList = Arrays.stream(resources).sorted((o1, o2) -> StrUtil.compare(o1.getFilename(), o2.getFilename(), true)).filter(resource -> !StrUtil.containsIgnoreCase(resource.getFilename(), "temp")).collect(Collectors.toList());
// 遍历
for (Resource resource : resourcesList) {
try (InputStream inputStream = resource.getInputStream()) {
String sql = IoUtil.read(inputStream, CharsetUtil.CHARSET_UTF_8);
String sha1 = SecureUtil.sha1(sql);
if (executeSqlLog.contains(sha1)) {
// 已经执行过啦,不再执行
continue;
}
sqlFileNow = resource.getFilename();
int rows = Db.use(dsFactory.getDataSource()).execute(sql);
DefaultSystemLog.getLog().info("exec init SQL file: {} complete, and affected rows is: {}", sqlFileNow, rows);
executeSqlLog.add(sha1);
} catch (IOException ignored) {
}
}
instance.saveExecuteSqlLog(executeSqlLog);
GlobalDSFactory.set(dsFactory);
//
} catch (Exception e) {
DefaultSystemLog.getLog().error("初始化数据库失败 {}", sqlFileNow, e);
System.exit(0);
return;
}
instance.initOk();
// json load to db
InitDb.loadJsonToDb();
Console.log("h2 db Successfully loaded, url is 【{}】", dbUrl);
if (JpomManifest.getInstance().isDebug()) {
//
} else {
if (serverExtConfigBean.isH2ConsoleEnabled() && StrUtil.equals(dbExtConfig.getUserName(), DbConfig.DEFAULT_USER_OR_AUTHORIZATION) && StrUtil.equals(dbExtConfig.getUserPwd(), DbConfig.DEFAULT_USER_OR_AUTHORIZATION)) {
Console.error("【安全警告】数据库账号密码使用默认的情况下不建议开启 h2 数据 web 控制台");
System.exit(-2);
}
}
}
use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class CheckMonitor method init.
@PreLoadMethod
private static void init() {
// 缓存检测调度
CronUtils.upsert("cache_manger_schedule", "0 0/10 * * * ?", () -> {
BuildUtil.reloadCacheSize();
ConfigBean.getInstance().dataSize();
});
// 开启版本检测调度
CronUtils.upsert("system_monitor", "0 0 0,12 * * ?", () -> {
try {
BackupInfoService backupInfoService = SpringUtil.getBean(BackupInfoService.class);
backupInfoService.checkAutoBackup();
//
RemoteVersion.loadRemoteInfo();
} catch (Exception e) {
DefaultSystemLog.getLog().error("系统调度执行出现错误", e);
}
});
// 拉取 脚本模版日志
CronUtils.upsert("pull_script_log", "0 0/1 * * * ?", () -> {
NodeService nodeService = SpringUtil.getBean(NodeService.class);
NodeScriptServer nodeScriptServer = SpringUtil.getBean(NodeScriptServer.class);
List<String> nodeIds = nodeScriptServer.hasScriptNode();
if (nodeIds == null) {
return;
}
for (String nodeId : nodeIds) {
NodeModel nodeModel = nodeService.getByKey(nodeId);
if (nodeModel == null) {
continue;
}
ThreadUtil.execute(() -> CheckMonitor.pullScriptLogItem(nodeModel));
}
});
// 异步加载
CheckMonitor.asyncLoad();
}
Aggregations