Use global variable strapi instead of context to restart server

This commit is contained in:
Aurélien Georget 2015-12-17 22:42:19 +01:00
parent cf0b0035d7
commit 66b7f59695

View File

@ -17,13 +17,11 @@ const async = require('async');
*/
module.exports = cb => {
const self = this;
console.log();
// Update the Strapi status (might be used
// by the core or some hooks).
this.reloading = true;
strapi.reloading = true;
// Async module loader to rebuild a
// dictionary of the application.
@ -31,12 +29,12 @@ module.exports = cb => {
// Rebuild the dictionaries.
dictionaries: cb => {
self.on('hook:_config:reloaded', () => {
self.on('hook:_api:reloaded', () => cb());
self.hooks._api.reload();
strapi.on('hook:_config:reloaded', () => {
strapi.on('hook:_api:reloaded', () => cb());
strapi.hooks._api.reload();
});
self.hooks._config.reload();
strapi.hooks._config.reload();
}
},
@ -46,23 +44,23 @@ module.exports = cb => {
// Just in case there is an error.
if (err) {
self.log.error('Impossible to reload the server');
self.log.error('Please restart the server manually');
self.stop();
strapi.log.error('Impossible to reload the server');
strapi.log.error('Please restart the server manually');
strapi.stop();
}
// Tell the application the framework is reloading
// (might be used by some hooks).
self.reloading = true;
strapi.reloading = true;
// Run adapters installation
if (cluster.isMaster) {
self.hooks.waterline.installation();
strapi.hooks.waterline.installation();
++count;
if (_.isPlainObject(self.config.views) && !_.isBoolean(self.config.views)) {
self.hooks.views.installation();
if (_.isPlainObject(strapi.config.views) && !_.isBoolean(strapi.config.views)) {
strapi.hooks.views.installation();
++count;
}
@ -70,32 +68,32 @@ module.exports = cb => {
const installed = _.after(count, () => {
if (_.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers > 0) {
self.log.warn('Application is restarting...');
strapi.log.warn('Application is restarting...');
console.log();
}
// Teardown Waterline adapters and
// reload the Waterline ORM.
self.after('hook:waterline:reloaded', () => {
self.after('hook:router:reloaded', () => {
strapi.after('hook:waterline:reloaded', () => {
strapi.after('hook:router:reloaded', () => {
process.nextTick(() => cb());
// Update `strapi` status.
self.reloaded = true;
self.reloading = false;
strapi.reloaded = true;
strapi.reloading = false;
// Finally inform the developer everything seems ok.
if (cluster.isMaster && _.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers < 1) {
self.log.info('Application\'s dictionnary updated');
self.log.warn('You still need to restart your server to fully enjoy changes...');
strapi.log.info('Application\'s dictionnary updated');
strapi.log.warn('You still need to restart your server to fully enjoy changes...');
}
self.once('restart:done', function () {
strapi.once('restart:done', function () {
strapi.log.info('Application successfully restarted');
});
if (cluster.isMaster) {
_.forEach(cluster.workers, worker => worker.on('message', () => self.emit('restart:done')));
_.forEach(cluster.workers, worker => worker.on('message', () => strapi.emit('restart:done')));
}
// Kill every worker processes.
@ -103,18 +101,18 @@ module.exports = cb => {
});
// Reloading the router.
self.hooks.router.reload();
strapi.hooks.router.reload();
});
// Reloading the ORM.
self.hooks.waterline.reload();
strapi.hooks.waterline.reload();
});
self.after('hook:waterline:installed', () => {
strapi.after('hook:waterline:installed', () => {
installed();
});
self.after('hook:views:installed', () => {
strapi.after('hook:views:installed', () => {
installed();
});
});