Merge branch 'bg-status-on-shutdown'

This commit is contained in:
Brian Gough 2019-08-15 09:42:00 +01:00
commit a7a161556f
3 changed files with 14 additions and 5 deletions

View file

@ -58,6 +58,9 @@ app.get "/", (req, res, next) ->
res.send "real-time-sharelatex is alive"
app.get "/status", (req, res, next) ->
if Settings.shutDownInProgress
res.send 503 # Service unavailable
else
res.send "real-time-sharelatex is alive"
app.get "/debug/events", (req, res, next) ->
@ -116,17 +119,17 @@ shutdownCleanly = (signal) ->
shutdownCleanly(signal)
, 10000
shutDownInProgress = false
Settings.shutDownInProgress = false
if Settings.shutdownDrainTimeWindow?
Settings.forceDrainMsDelay = parseInt(Settings.shutdownDrainTimeWindow, 10)
logger.log shutdownDrainTimeWindow: Settings.shutdownDrainTimeWindow,"shutdownDrainTimeWindow enabled"
for signal in ['SIGINT', 'SIGHUP', 'SIGQUIT', 'SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGABRT']
process.on signal, ->
if shutDownInProgress
if Settings.shutDownInProgress
logger.log signal: signal, "shutdown already in progress, ignoring signal"
return
else
shutDownInProgress = true
Settings.shutDownInProgress = true
logger.log signal: signal, "received interrupt, starting drain over #{Settings.shutdownDrainTimeWindow} mins"
DrainManager.startDrainTimeWindow(io, Settings.shutdownDrainTimeWindow)
shutdownCleanly(signal)

View file

@ -40,7 +40,8 @@ module.exports = DocumentUpdaterManager =
logger.log project_id:project_id, "deleting project from document updater"
timer = new metrics.Timer("delete.mongo.project")
# flush the project in the background when all users have left
url = "#{settings.apis.documentupdater.url}/project/#{project_id}?background=true"
url = "#{settings.apis.documentupdater.url}/project/#{project_id}?background=true" +
(if settings.shutDownInProgress then "&shutdown=true" else "")
request.del url, (err, res, body)->
timer.done()
if err?

View file

@ -39,6 +39,11 @@ module.exports = Router =
app.post "/drain", httpAuth, HttpApiController.startDrain
session.on 'connection', (error, client, session) ->
if settings.shutDownInProgress
client.emit("connectionRejected", {message: "retry"})
client.disconnect()
return
if client? and error?.message?.match(/could not look up session by key/)
logger.warn err: error, client: client?, session: session?, "invalid session"
# tell the client to reauthenticate if it has an invalid session key