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

alibaba-archive/hot-restart

Repository files navigation

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

About

hot restart node server in cluster mode

Resources

License

Stars

Watchers

Forks

Packages

No packages published