Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ clusterMaster.quitHard()
Set the cluster size to `n`. This will disconnect extra nodes and/or
spin up new nodes, as needed. Done by default on restarts.

### clusterMaster.restart(cb)
### clusterMaster.restart(env, cb)

One by one, shut down nodes and spin up new ones. Callback is called
when finished.
One by one, shut down nodes and spin up new ones. New workers will
receive `env`, instead of the envs passed in config. Callback is called
when finished. `env` and `cb` are optional.

### clusterMaster.quit()

Expand Down Expand Up @@ -129,7 +130,7 @@ The REPL provides you with access to these objects or functions:
* `help` - display these commands
* `repl` - access the REPL
* `resize(n)` - resize the cluster to `n` workers
* `restart(cb)` - gracefully restart workers, cb is optional
* `restart(env, cb)` - gracefully restart workers, env and cb are optional
* `stop()` - gracefully stop workers and master
* `kill()` - forcefully kill workers and master
* `cluster` - node.js cluster module
Expand Down
9 changes: 7 additions & 2 deletions cluster-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function setupRepl () {
'help - display these commands',
'repl - access the REPL',
'resize(n) - resize the cluster to `n` workers',
'restart(cb) - gracefully restart workers, cb is optional',
'restart(env, cb) - gracefully restart workers, env and cb are optional',
'stop() - gracefully stop workers and master',
'kill() - forcefully kill workers and master',
'cluster - node.js cluster module',
Expand Down Expand Up @@ -304,14 +304,19 @@ function forkListener () {
})
}

function restart (cb) {
function restart (env_, cb) {
if (restarting) {
debug("Already restarting. Cannot restart yet.")
return
}

restarting = true

if (arguments.length == 1 && env_ && {}.toString.call(env_) == '[object Function]')
cb = env_, env_ = undefined

if (env_) env = env_

// graceful restart.
// all the existing workers get killed, and this
// causes new ones to be spawned. If there aren't
Expand Down