Boot checks

This commit is contained in:
devezhao 2019-05-07 13:31:06 +08:00
parent b58ae4a744
commit 9b6b67449f
3 changed files with 25 additions and 36 deletions

View file

@ -1,27 +0,0 @@
/*
rebuild - Building your business-systems freely.
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rebuild.server;
/**
* @author devezhao
* @since 01/02/2019
*/
public interface Failover {
}

View file

@ -21,22 +21,22 @@ package com.rebuild.server;
import java.io.File;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.sql.DataSource;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.jdbc.datasource.DataSourceUtils;
import com.alibaba.fastjson.JSON;
import com.rebuild.server.helper.AesPreferencesConfigurer;
import com.rebuild.server.helper.cache.CommonCache;
import com.rebuild.utils.JSONUtils;
import cn.devezhao.commons.CodecUtils;
import cn.devezhao.commons.ThrowableUtils;
import cn.devezhao.persist4j.util.SqlHelper;
/**
* 服务状态检查/监控
@ -71,6 +71,13 @@ public final class ServerStatus {
}
return true;
}
/**
* @return
*/
public static boolean isDatabaseOK() {
return checkDatabase().success;
}
/**
* 系统状态检查
@ -90,7 +97,7 @@ public final class ServerStatus {
}
return isStatusOK();
}
/**
* 数据库连接
*
@ -99,14 +106,19 @@ public final class ServerStatus {
protected static Status checkDatabase() {
String name = "Database";
try {
DataSource ds = Application.getPersistManagerFactory().getDataSource();
Connection c = DataSourceUtils.getConnection(ds);
Class.forName(com.mysql.jdbc.Driver.class.getName());
Connection c = DriverManager.getConnection(
Application.getBean(AesPreferencesConfigurer.class).getItem("db.url"),
Application.getBean(AesPreferencesConfigurer.class).getItem("db.user"),
Application.getBean(AesPreferencesConfigurer.class).getItem("db.passwd"));
SqlHelper.close(c);
// DataSource ds = Application.getPersistManagerFactory().getDataSource();
// Connection c = DataSourceUtils.getConnection(ds);
// DatabaseMetaData dmd = c.getMetaData();
// String dbName = dmd.getDatabaseProductName() + dmd.getDatabaseProductVersion();
// name += "/" + dbName;
DataSourceUtils.releaseConnection(c, ds);
// DataSourceUtils.releaseConnection(c, ds);
} catch (Exception ex) {
return Status.error(name, ThrowableUtils.getRootCause(ex).getLocalizedMessage());
}

View file

@ -10,7 +10,11 @@
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="${pageContext.request.contextPath}/assets/img/favicon.png">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/assets/css/rb-base.css">
<title>系统状态</title>
<style type="text/css">
.block{margin:0 auto;max-width:1000px;padding:0 14px;margin-top:30px;}