mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	Fix cluster strapi.stop
This commit is contained in:
		
							parent
							
								
									d855d99fd1
								
							
						
					
					
						commit
						54c7f03c31
					
				@ -73,7 +73,9 @@ module.exports = function() {
 | 
			
		||||
      setFilesToWatch(process.cwd());
 | 
			
		||||
 | 
			
		||||
      if (cluster.isMaster) {
 | 
			
		||||
        cluster.on('message', () => {
 | 
			
		||||
        cluster.on('message', (worker, message) => {
 | 
			
		||||
          if (message !== 'reload') return;
 | 
			
		||||
 | 
			
		||||
          strapi.log.info('The server is restarting\n');
 | 
			
		||||
 | 
			
		||||
          _.forEach(cluster.workers, worker => worker.kill());
 | 
			
		||||
@ -81,6 +83,14 @@ module.exports = function() {
 | 
			
		||||
          cluster.fork();
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        cluster.on('message', (worker, message) => {
 | 
			
		||||
          if (message !== 'stop') return;
 | 
			
		||||
 | 
			
		||||
          _.forEach(cluster.workers, worker => worker.kill());
 | 
			
		||||
 | 
			
		||||
          process.exit(0);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        cluster.fork();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -137,6 +137,9 @@ class Strapi extends EventEmitter {
 | 
			
		||||
  stop() {
 | 
			
		||||
    // Destroy server and available connections.
 | 
			
		||||
    this.server.destroy();
 | 
			
		||||
 | 
			
		||||
    if (cluster.isWorker && process.env.NODE_ENV === 'development' && this.config.currentEnvironment.server.autoReload === true) process.send('stop');
 | 
			
		||||
 | 
			
		||||
    // Kill process.
 | 
			
		||||
    process.exit(0);
 | 
			
		||||
  }
 | 
			
		||||
@ -162,7 +165,7 @@ class Strapi extends EventEmitter {
 | 
			
		||||
 | 
			
		||||
  reload() {
 | 
			
		||||
    const reload = function() {
 | 
			
		||||
      if (cluster.isWorker && process.env.NODE_ENV === 'development' && this.config.currentEnvironment.server.autoReload === true) process.send('message');
 | 
			
		||||
      if (cluster.isWorker && process.env.NODE_ENV === 'development' && this.config.currentEnvironment.server.autoReload === true) process.send('reload');
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    reload.isReloading = false;
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,7 @@
 | 
			
		||||
module.exports = function reload() {
 | 
			
		||||
  try {
 | 
			
		||||
    const reload = function() {
 | 
			
		||||
      if (cluster.isWorker && process.env.NODE_ENV === 'development' && this.config.environments[this.config.environment].server.reload === true) process.send('message');
 | 
			
		||||
      if (cluster.isWorker && process.env.NODE_ENV === 'development' && this.config.environments[this.config.environment].server.reload === true) process.send('reload');
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    reload.isReloading = false;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user