Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Latest commit

 

History

History
61 lines (41 loc) · 1.27 KB

README.md

File metadata and controls

61 lines (41 loc) · 1.27 KB

hot-restart

NPM version Build Status

hot restart a node server in cluster mode.

Install

npm install hot-restart

Usage

in master:

var restarter = require('hot-restart')();

restarter.on('restart', fuction () {
  // fork new workers
});

// when new work forked
restarter.add(newWorker);

// when old work died
restarter.remove(oldWorker);

in worker:

var restarter = require('hot-restart/worker');

restarter({
  disconnectTime: 1000,
  exitTime: 2000
});

use signal to hot restart the server: kill -PIPE 3132

checkout the example.

Flow

  1. in master, require('restarter')(opts), and add every worker to restarter.
  2. in workers, require('restarter/worker')(opts), set disconnect options.
  3. kill -PIPE 3132 to tell master restart.
  4. master will send restart message to all workers, then emit restart event, user need to start some new workers manually(also need to add these new works to restarter).
  5. old workers got restart message, will disconnect after disconnectTime and exit after exitTme.

License

MIT