log and show last restart on ACP dashboard

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 2551df80f7
commit 1f8b000530

@ -67,5 +67,6 @@
"graphs.page-views": "Page Views",
"graphs.unique-visitors": "Unique Visitors",
"graphs.registered-users": "Registered Users",
"graphs.anonymous-users": "Anonymous Users"
"graphs.anonymous-users": "Anonymous Users",
"last-restarted-by": "Last restarted by"
}

@ -9,6 +9,8 @@ var versions = require('../../admin/versions');
var db = require('../../database');
var meta = require('../../meta');
var plugins = require('../../plugins');
var user = require('../../user');
var utils = require('../../utils');
var dashboardController = module.exports;
@ -51,6 +53,9 @@ dashboardController.get = function (req, res, next) {
next(null, err ? null : result);
});
},
lastrestart: function (next) {
getLastRestart(next);
},
}, next);
},
function (results) {
@ -65,6 +70,7 @@ dashboardController.get = function (req, res, next) {
notices: results.notices,
stats: results.stats,
canRestart: !!process.send,
lastrestart: results.lastrestart,
});
},
], next);
@ -128,3 +134,24 @@ function getGlobalField(field, callback) {
callback(err, parseInt(count, 10) || 0);
});
}
function getLastRestart(callback) {
var lastrestart;
async.waterfall([
function (next) {
db.getObject('lastrestart', next);
},
function (_lastrestart, next) {
lastrestart = _lastrestart;
if (!lastrestart) {
return callback();
}
user.getUserData(lastrestart.uid, next);
},
function (userData, next) {
lastrestart.user = userData;
lastrestart.timestampISO = utils.toISOString(lastrestart.timestamp);
next(null, lastrestart);
},
], callback);
}

@ -59,14 +59,23 @@ SocketAdmin.before = function (socket, method, data, next) {
};
SocketAdmin.restart = function (socket, data, callback) {
logRestart(socket);
meta.restart();
callback();
};
function logRestart(socket) {
events.log({
type: 'restart',
uid: socket.uid,
ip: socket.ip,
});
meta.restart();
callback();
};
db.setObject('lastrestart', {
uid: socket.uid,
ip: socket.ip,
timestamp: Date.now(),
});
}
SocketAdmin.reload = function (socket, data, callback) {
async.waterfall([
@ -80,12 +89,7 @@ SocketAdmin.reload = function (socket, data, callback) {
ip: socket.ip,
});
events.log({
type: 'restart',
uid: socket.uid,
ip: socket.ip,
});
logRestart(socket);
meta.restart();
next();
},

@ -124,6 +124,10 @@
<button class="btn btn-block btn-warning restart"<!-- IF !canRestart --> disabled<!-- END -->>[[admin/general/dashboard:restart]]</button>
<button class="btn btn-block btn-danger rebuild-and-restart"<!-- IF !canRestart --> disabled<!-- END -->>[[admin/general/dashboard:rebuild-and-restart]]</button>
</p>
<!-- IF lastrestart -->
<p>[[admin/general/dashboard:last-restarted-by]]</p>
<p><a href="{config.relative_path}/uid/{lastrestart.uid}">{lastrestart.user.username}</a> <span>{lastrestart.timestampISO}</span></p>
<!-- ENDIF lastrestart -->
<p class="<!-- IF canRestart -->help-block<!-- ELSE -->alert alert-warning<!-- END -->">
<!-- IF canRestart -->
[[admin/general/dashboard:restart-warning]]

Loading…
Cancel
Save