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.page-views": "Page Views",
"graphs.unique-visitors": "Unique Visitors", "graphs.unique-visitors": "Unique Visitors",
"graphs.registered-users": "Registered Users", "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 db = require('../../database');
var meta = require('../../meta'); var meta = require('../../meta');
var plugins = require('../../plugins'); var plugins = require('../../plugins');
var user = require('../../user');
var utils = require('../../utils');
var dashboardController = module.exports; var dashboardController = module.exports;
@ -51,6 +53,9 @@ dashboardController.get = function (req, res, next) {
next(null, err ? null : result); next(null, err ? null : result);
}); });
}, },
lastrestart: function (next) {
getLastRestart(next);
},
}, next); }, next);
}, },
function (results) { function (results) {
@ -65,6 +70,7 @@ dashboardController.get = function (req, res, next) {
notices: results.notices, notices: results.notices,
stats: results.stats, stats: results.stats,
canRestart: !!process.send, canRestart: !!process.send,
lastrestart: results.lastrestart,
}); });
}, },
], next); ], next);
@ -128,3 +134,24 @@ function getGlobalField(field, callback) {
callback(err, parseInt(count, 10) || 0); 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) { SocketAdmin.restart = function (socket, data, callback) {
logRestart(socket);
meta.restart();
callback();
};
function logRestart(socket) {
events.log({ events.log({
type: 'restart', type: 'restart',
uid: socket.uid, uid: socket.uid,
ip: socket.ip, ip: socket.ip,
}); });
meta.restart(); db.setObject('lastrestart', {
callback(); uid: socket.uid,
}; ip: socket.ip,
timestamp: Date.now(),
});
}
SocketAdmin.reload = function (socket, data, callback) { SocketAdmin.reload = function (socket, data, callback) {
async.waterfall([ async.waterfall([
@ -80,12 +89,7 @@ SocketAdmin.reload = function (socket, data, callback) {
ip: socket.ip, ip: socket.ip,
}); });
events.log({ logRestart(socket);
type: 'restart',
uid: socket.uid,
ip: socket.ip,
});
meta.restart(); meta.restart();
next(); 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-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> <button class="btn btn-block btn-danger rebuild-and-restart"<!-- IF !canRestart --> disabled<!-- END -->>[[admin/general/dashboard:rebuild-and-restart]]</button>
</p> </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 -->"> <p class="<!-- IF canRestart -->help-block<!-- ELSE -->alert alert-warning<!-- END -->">
<!-- IF canRestart --> <!-- IF canRestart -->
[[admin/general/dashboard:restart-warning]] [[admin/general/dashboard:restart-warning]]

Loading…
Cancel
Save