mirror of
https://github.com/getrebuild/rebuild.git
synced 2024-09-20 07:25:54 +08:00
servers-status
This commit is contained in:
parent
73a3683931
commit
016f3ce4f6
|
@ -2,7 +2,7 @@
|
|||
"name": "rebuild-babel",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"build": "babel ../src/main/webapp/assets/js --out-dir ../src/main/webapp/assets/js/dist"
|
||||
"build": "babel '../src/main/webapp/assets/js' --out-dir '../src/main/webapp/assets/js/dist'"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -29,3 +29,5 @@ hs_err_pid*
|
|||
/.project
|
||||
/bin/
|
||||
.DS_Store
|
||||
/.babel/node_modules/
|
||||
/.babel/package-lock.json
|
||||
|
|
|
@ -70,7 +70,11 @@ public final class Application {
|
|||
* 初始化
|
||||
*/
|
||||
protected void init(long startingAt) {
|
||||
// Security.addProvider(new BouncyCastleProvider());
|
||||
boolean serversReady = ServersStatus.quickcheck();
|
||||
if (!serversReady) {
|
||||
LOG.info("Rebuild Booting failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 自定义实体
|
||||
LOG.info("Loading customized entities ...");
|
||||
|
|
94
src/main/java/com/rebuild/server/ServersStatus.java
Normal file
94
src/main/java/com/rebuild/server/ServersStatus.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
rebuild - Building your system 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;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.EMPTY;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
|
||||
import cn.devezhao.commons.ThrowableUtils;
|
||||
|
||||
/**
|
||||
* 各服务状态
|
||||
*
|
||||
* @author devezhao
|
||||
* @since 10/31/2018
|
||||
*/
|
||||
public class ServersStatus {
|
||||
|
||||
private static final Map<String, String> LAST_STATUS = new ConcurrentHashMap<>();
|
||||
static {
|
||||
LAST_STATUS.put("DataSource", EMPTY);
|
||||
}
|
||||
/**
|
||||
* 最近检查状态
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> getLastStatus() {
|
||||
return Collections.unmodifiableMap(LAST_STATUS);
|
||||
}
|
||||
/**
|
||||
* 服务正常
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isStatusOK() {
|
||||
for (Map.Entry<String, String> e : getLastStatus().entrySet()) {
|
||||
if (e.getValue() != EMPTY) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动检查
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean quickcheck() {
|
||||
String DataSource = checkingDataSource();
|
||||
Application.LOG.info("Checking DataSource : " + (DataSource == EMPTY ? "[OK]" : DataSource));
|
||||
LAST_STATUS.put("DataSource", DataSource);
|
||||
|
||||
return DataSource == EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected static String checkingDataSource() {
|
||||
try {
|
||||
DataSource ds = Application.getPersistManagerFactory().getDataSource();
|
||||
Connection c = DataSourceUtils.getConnection(ds);
|
||||
DataSourceUtils.releaseConnection(c, ds);
|
||||
} catch (Exception ex) {
|
||||
return ThrowableUtils.getRootCause(ex).getLocalizedMessage();
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.RebuildException;
|
||||
import com.rebuild.server.ServerListener;
|
||||
import com.rebuild.server.ServersStatus;
|
||||
import com.rebuild.utils.AppUtils;
|
||||
import com.rebuild.web.admin.AdminEntryControll;
|
||||
|
||||
|
@ -50,6 +51,12 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
|
|||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) throws Exception {
|
||||
|
||||
if (!ServersStatus.isStatusOK()) {
|
||||
ServletUtils.forward(request, response, "/servers-status.jsp");
|
||||
return false;
|
||||
}
|
||||
|
||||
Application.getSessionStore().storeLastActive(request);
|
||||
|
||||
boolean chain = super.preHandle(request, response, handler);
|
||||
|
|
|
@ -15,19 +15,23 @@ errorCode = errorCode == null ? 400 : errorCode;
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="/_include/Head.jsp"%>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" type="text/css" href="${baseUrl}/assets/lib/material-design-iconic-font.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="${baseUrl}/assets/css/rb-base.css">
|
||||
<link rel="stylesheet" type="text/css" href="${baseUrl}/assets/css/rb-page.css">
|
||||
<title>提示</title>
|
||||
</head>
|
||||
<body class="rb-splash-screen">
|
||||
<div class="rb-wrapper rb-error">
|
||||
<div class="rb-content" style="margin:0">
|
||||
<div class="rb-content m-0">
|
||||
<div class="main-content container-fluid">
|
||||
<div class="error-container">
|
||||
<div class="error-number"><%=errorCode%></div>
|
||||
<div class="error-description"><%=errorMsg%></div>
|
||||
<div class="error-goback-button">
|
||||
<a class="btn btn-xl btn-primary hide J_home" href="${baseUrl}/dashboard/home">返回首页</a>
|
||||
<a class="btn btn-xl btn-primary hide J_reload" href="javascript:;" onclick="_reload()">刷新</a>
|
||||
<a class="btn btn-xl btn-primary hide J_reload" href="javascript:;" onclick="location.reload(true)">刷新</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -39,9 +43,6 @@ errorCode = errorCode == null ? 400 : errorCode;
|
|||
if (self != top) $('.J_reload').removeClass('hide')
|
||||
else $('.J_home').removeClass('hide')
|
||||
})()
|
||||
_reload = function(){
|
||||
location.reload(true)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
34
src/main/webapp/servers-status.jsp
Normal file
34
src/main/webapp/servers-status.jsp
Normal file
|
@ -0,0 +1,34 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<%@ page import="com.rebuild.server.ServersStatus"%>
|
||||
<%@ page import="java.util.Map"%>
|
||||
<%@ page import="com.rebuild.web.common.SimplePageForward"%>
|
||||
<%
|
||||
SimplePageForward.setPageAttribute(request);
|
||||
%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" type="text/css" href="${baseUrl}/assets/css/rb-base.css">
|
||||
<title>服务不可用</title>
|
||||
<style type="text/css">
|
||||
h4{padding:16px 32px;padding-bottom:6px}
|
||||
.error-description{background-color:#fff;border:1px solid #ccc;padding:16px}
|
||||
.error-description dl{margin:0}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h4>以下服务不可用</h4>
|
||||
<div class="error-description">
|
||||
<% for (Map.Entry<String, String> e : ServersStatus.getLastStatus().entrySet()) { %>
|
||||
<dl class="row">
|
||||
<dt class="col-2"><%=e.getKey()%></dt>
|
||||
<dd class="col-10"><%=e.getValue()%></dd>
|
||||
</dl>
|
||||
<% }%>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue