mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add load balance http endpoints to shut box down
This commit is contained in:
parent
c33c9f8fc7
commit
2384eb83d9
2 changed files with 30 additions and 11 deletions
|
@ -174,7 +174,11 @@ os = require "os"
|
|||
|
||||
STATE = "up"
|
||||
|
||||
server = net.createServer (socket) ->
|
||||
process.on "SIGHUP", ->
|
||||
console.log "got SIGHUP event"
|
||||
STATE = "down"
|
||||
|
||||
loadTcpServer = net.createServer (socket) ->
|
||||
socket.on "error", (err)->
|
||||
if err.code == "ECONNRESET"
|
||||
# this always comes up, we don't know why
|
||||
|
@ -182,7 +186,7 @@ server = net.createServer (socket) ->
|
|||
logger.err err:err, "error with socket on load check"
|
||||
socket.destroy()
|
||||
|
||||
if STATE == "up" and Settings.load_balancer_agent.report_load
|
||||
if STATE == "up" and Settings.internal.load_balancer_agent.report_load
|
||||
currentLoad = os.loadavg()[0]
|
||||
|
||||
# staging clis's have 1 cpu core only
|
||||
|
@ -201,26 +205,38 @@ server = net.createServer (socket) ->
|
|||
socket.write("#{STATE}\n", "ASCII")
|
||||
socket.end()
|
||||
|
||||
loadHttpServer = express()
|
||||
|
||||
loadHttpServer.post "/state/up", (req, res, next) ->
|
||||
STATE = "up"
|
||||
logger.info "getting message to set server to down"
|
||||
res.sendStatus 204
|
||||
|
||||
loadHttpServer.post "/state/down", (req, res, next) ->
|
||||
STATE = "down"
|
||||
logger.info "getting message to set server to down"
|
||||
res.sendStatus 204
|
||||
|
||||
port = (Settings.internal?.clsi?.port or 3013)
|
||||
host = (Settings.internal?.clsi?.host or "localhost")
|
||||
load_port = Settings.internal.clsi.load_port or 3048
|
||||
|
||||
|
||||
load_tcp_port = Settings.internal.load_balancer_agent.load_port
|
||||
load_http_port = Settings.internal.load_balancer_agent.local_port
|
||||
|
||||
if !module.parent # Called directly
|
||||
app.listen port, host, (error) ->
|
||||
logger.info "CLSI starting up, listening on #{host}:#{port}"
|
||||
|
||||
server.listen load_port, host, (error) ->
|
||||
loadTcpServer.listen load_tcp_port, host, (error) ->
|
||||
throw error if error?
|
||||
logger.info "Load agent listening on load port #{load_port}"
|
||||
logger.info "Load tcp agent listening on load port #{load_tcp_port}"
|
||||
|
||||
loadHttpServer.listen load_http_port, host, (error) ->
|
||||
throw error if error?
|
||||
logger.info "Load http agent listening on load port #{load_http_port}"
|
||||
|
||||
module.exports = app
|
||||
|
||||
|
||||
|
||||
setInterval () ->
|
||||
ProjectPersistenceManager.clearExpiredProjects()
|
||||
, tenMinutes = 10 * 60 * 1000
|
||||
|
|
|
@ -20,7 +20,11 @@ module.exports =
|
|||
clsi:
|
||||
port: 3013
|
||||
host: process.env["LISTEN_ADDRESS"] or "localhost"
|
||||
|
||||
|
||||
load_balancer_agent:
|
||||
report_load:true
|
||||
load_port: 3048
|
||||
local_port: 3049
|
||||
apis:
|
||||
clsi:
|
||||
url: "http://#{process.env['CLSI_HOST'] or 'localhost'}:3013"
|
||||
|
@ -29,6 +33,7 @@ module.exports =
|
|||
project_cache_length_ms: 1000 * 60 * 60 * 24
|
||||
parallelFileDownloads:1
|
||||
|
||||
|
||||
if process.env["DOCKER_RUNNER"]
|
||||
module.exports.clsi =
|
||||
dockerRunner: process.env["DOCKER_RUNNER"] == "true"
|
||||
|
@ -52,5 +57,3 @@ if process.env["DOCKER_RUNNER"]
|
|||
module.exports.path.sandboxedCompilesHostDir = process.env["COMPILES_HOST_DIR"]
|
||||
|
||||
module.exports.path.synctexBinHostPath = process.env["SYNCTEX_BIN_HOST_PATH"]
|
||||
console.log "configggggg"
|
||||
console.log module.exports
|
||||
|
|
Loading…
Reference in a new issue