mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 16:32:08 +00:00
mvp for safe shutdown
This commit is contained in:
parent
fc2d2405f4
commit
9a851d6cce
1 changed files with 17 additions and 0 deletions
|
@ -78,3 +78,20 @@ server.listen port, host, (error) ->
|
|||
|
||||
# Stop huge stack traces in logs from all the socket.io parsing steps.
|
||||
Error.stackTraceLimit = 10
|
||||
|
||||
|
||||
shutdownCleanly = (signal) ->
|
||||
return () ->
|
||||
logger.log signal: signal, "received interrupt, cleaning up"
|
||||
connectedClients = io.sockets.clients()?.length
|
||||
logger.log {connectedClients, signal}, "looking to shut down process"
|
||||
if connectedClients == 0
|
||||
logger.log("no clients connected, exiting")
|
||||
process.exit()
|
||||
else
|
||||
setTimeout () ->
|
||||
shutdownCleanly(signal)
|
||||
, 10000
|
||||
|
||||
for signal in ['SIGINT', 'SIGHUP', 'SIGQUIT', 'SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGABRT']
|
||||
process.on signal, shutdownCleanly(signal)
|
||||
|
|
Loading…
Reference in a new issue