Handle SIGINT and SIGTERM to exit gracefully
This commit is contained in:
1 parent
9f85ead558
commit
34de9c7e7d
2 files changed
+34
-14
No files matched your search
+15
-3
@@ -24,10 +24,11 @@ cluster.on('listening', (worker, address) ->
|
||||
util.log("Worker #{worker.process.pid} listening to #{address.address}:#{address.port}")
|
||||
)
|
||||
|
||||
cluster.on('exit', (worker, code, signal) ->
|
||||
util.log("Worker #{worker.process.pid} died (#{worker.process.exitCode})")
|
||||
restartWorker = (worker, code, signal) ->
|
||||
util.log("Worker #{worker.process.pid} died (#{worker.process.exitCode}) #{signal}")
|
||||
cluster.fork()
|
||||
)
|
||||
|
||||
cluster.on('exit', restartWorker)
|
||||
|
||||
|
||||
start = (service) ->
|
||||
@@ -43,4 +44,15 @@ start = (service) ->
|
||||
cluster.fork()
|
||||
|
||||
|
||||
process.on('SIGINT', () ->
|
||||
cluster.removeListener('exit', restartWorker)
|
||||
)
|
||||
|
||||
process.on('SIGTERM', () ->
|
||||
cluster.removeListener('exit', restartWorker)
|
||||
for id of cluster.workers
|
||||
cluster.workers[id].kill()
|
||||
)
|
||||
|
||||
|
||||
exports.start = start
|
||||
Reference in new issue
Block a user