diff --git a/services/real-time/app.coffee b/services/real-time/app.coffee index 40d2a151fc..069b4d6837 100644 --- a/services/real-time/app.coffee +++ b/services/real-time/app.coffee @@ -58,7 +58,10 @@ app.get "/", (req, res, next) -> res.send "real-time-sharelatex is alive" app.get "/status", (req, res, next) -> - res.send "real-time-sharelatex is alive" + if Settings.shutDownInProgress + res.send 503 # Service unavailable + else + res.send "real-time-sharelatex is alive" app.get "/debug/events", (req, res, next) -> Settings.debugEvents = parseInt(req.query?.count,10) || 20 @@ -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) diff --git a/services/real-time/app/coffee/DocumentUpdaterManager.coffee b/services/real-time/app/coffee/DocumentUpdaterManager.coffee index 40ef992d8f..9968b78753 100644 --- a/services/real-time/app/coffee/DocumentUpdaterManager.coffee +++ b/services/real-time/app/coffee/DocumentUpdaterManager.coffee @@ -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? diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index a7ed73c981..aaa8b59a18 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -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