添加自动重启

This commit is contained in:
suwings 2018-02-10 16:34:18 +08:00
parent 95f84cbf56
commit 990e2787c3
4 changed files with 68 additions and 9 deletions

View File

@ -15,6 +15,7 @@ class MinecraftServer extends ServerProcess {
this.dataModel.name = name;
this.dataModel.createDate = now;
this.dataModel.lastDate = now;
this.dataModel.autoRestart = false; //是否自动重启
this.properties = undefined;

View File

@ -58,6 +58,23 @@
</div>
</div>
</div>
<div class="Panel PanelGreen">
<div class="PanelTitle">任务与机制</div>
<div class="PanelBody">
<transition name="slide-fade">
<div class="PanelItem" v-on:click="toAutoRestart(false)" v-if="serverData.autoRestart">
<span class="glyphicon glyphicon-retweet" aria-hidden="true"> </span> 自动重启:
<span style="color: #29b90c;">打开</span>
</div>
</transition>
<transition name="slide-fade">
<div class="PanelItem" v-on:click="toAutoRestart(true)" v-if="!serverData.autoRestart">
<span class="glyphicon glyphicon-retweet" aria-hidden="true"> </span> 自动重启:
<span style="color: #818181;">关闭</span>
</div>
</transition>
</div>
</div>
</div>
<div class="col-md-9">
<div class="Panel PanelRed">
@ -143,6 +160,9 @@
VIEW_MODEL.newVue('ConsolePanel', {
el: '#ConsolePanel',
methods: {
toAutoRestart: function () {
WS.sendMsg('server/console/autorestart', serverName);
},
toOnlineFs: function () {
var path = MCSERVER.URL("fs_auth/auth/" + encodeURIComponent(serverName));
window.open(path);

View File

@ -1,4 +1,6 @@
const { WebSocketObserver } = require('../../model/WebSocketModel');
const {
WebSocketObserver
} = require('../../model/WebSocketModel');
const counter = require('../../core/counter');
const response = require('../../helper/Response');
var serverModel = require('../../model/ServerModel');
@ -28,7 +30,7 @@ function selectWebsocket(serverName, callback) {
//服务器异常
serverModel.ServerManager().on('error', (data) => {
MCSERVER.infoLog('Error'.red,'[' + data.serverName + '] >>> 异常',true);
MCSERVER.infoLog('Error'.red, '[' + data.serverName + '] >>> 异常', true);
selectWebsocket(data.serverName, (socket) => {
response.wsMsgWindow(socket.ws, "服务器异常:" + data.msg);
});
@ -37,9 +39,18 @@ serverModel.ServerManager().on('error', (data) => {
//服务器退出
serverModel.ServerManager().on('exit', (data) => {
MCSERVER.log('[' + data.serverName + '] >>> 进程退出');
selectWebsocket(data.serverName, (socket) => {
response.wsMsgWindow(socket.ws, '服务器关闭');
});
let server = serverModel.ServerManager().getServer(data.serverName);
if (server.dataModel.autoRestart) {
//自动重启
setTimeout(() => {
serverModel.startServer(data.serverName);
}, 5000);
selectWebsocket(data.serverName,
(socket) => response.wsMsgWindow(socket.ws, '检测到服务器关闭,稍后将根据任务自动重启!'));
return;
}
selectWebsocket(data.serverName,
(socket) => response.wsMsgWindow(socket.ws, '服务器关闭'));
})
//服务器开启
@ -66,7 +77,7 @@ WebSocketObserver().listener('server/console/ws', (data) => {
data.WsSession['listenerQueue'] = serverT.getTerminalLog().length - 1;
response.wsMsgWindow(data.ws, '监听 [' + serverName + '] 终端');
return;
}else{
} else {
MCSERVER.log('[' + serverName + '] 拒绝用户 ' + userName + ' 控制台监听');
}
data.WsSession['console'] = undefined;
@ -90,7 +101,7 @@ serverModel.ServerManager().on('console', (data) => {
let consoleData = data.msg.replace(/\n/gim, '<br />');
//将输出载入历史记录 这里曾出现过 server 未定义bug情况不明已加保险
if(server) server.terminalLog(consoleData);
if (server) server.terminalLog(consoleData);
selectWebsocket(data.serverName, (socket) => {
socket.send({
@ -103,7 +114,9 @@ serverModel.ServerManager().on('console', (data) => {
});
const {autoLoadModule} = require("../../core/tools");
autoLoadModule('route/websocket/console','console/',(path)=>{
const {
autoLoadModule
} = require("../../core/tools");
autoLoadModule('route/websocket/console', 'console/', (path) => {
require(path);
});

View File

@ -0,0 +1,25 @@
const response = require('../../../helper/Response');
var serverModel = require('../../../model/ServerModel');
var userModel = require('../../../model/UserModel');
const permssion = require('../../../helper/Permission');
const {
WebSocketObserver
} = require('../../../model/WebSocketModel');
//开启服务器
WebSocketObserver().listener('server/console/autorestart', (data) => {
let serverName = data.body.trim();
let userName = data.WsSession.username;
if (permssion.isCanServer(userName, serverName)) {
let server = serverModel.ServerManager().getServer(serverName);
server.dataModel.autoRestart = !server.dataModel.autoRestart; //反之亦然
try {
server.save();
response.wsMsgWindow(data.ws, '更改设置成功!');
} catch (err) {
response.wsMsgWindow(data.ws, '更改设置失败!不正常,请刷新网页重新设置!');
}
return;
}
response.wsMsgWindow(data.ws, '权限不足!您并不拥有此服务器.');
});