openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
61 lines (43 loc) • 1.74 kB
JavaScript
var Keystore, KeystoreAPI, Q, authorisation, config, logger, server, utils;
logger = require('winston');
authorisation = require('../api/authorisation');
server = require("../server");
config = require("../config/config");
config.router = config.get('router');
config.api = config.get('api');
config.rerun = config.get('rerun');
config.polling = config.get('polling');
config.tcpAdapter = config.get('tcpAdapter');
Keystore = require('../model/keystore').Keystore;
KeystoreAPI = require("../api/keystore");
utils = require("../utils");
Q = require('q');
/*
* restart the server
*/
exports.restart = function*(next) {
var e, emailAddr, error, result;
if (authorisation.inGroup('admin', this.authenticated) === false) {
utils.logAndSetResponse(this, 403, "User " + this.authenticated.email + " is not an admin, API access to restart the server denied.", 'info');
return;
}
try {
emailAddr = this.authenticated.email;
result = (yield Q.nfcall(KeystoreAPI.getCertKeyStatus));
if (result) {
server.startRestartServerTimeout(function() {
return logger.info('User ' + emailAddr + ' has requested a Server Restart. Proceeding to restart servers...');
});
this.body = 'Server being restarted';
return this.status = 200;
} else {
logger.info('User ' + emailAddr + ' has requested a Server Restart with invalid certificate details. Cancelling restart...');
this.body = 'Certificates and Key did not match. Cancelling restart...';
return this.status = 400;
}
} catch (error) {
e = error;
return utils.logAndSetResponse(this, 400, "Could not restart the servers via the API: " + e, 'error');
}
};
//# sourceMappingURL=restart.js.map