2020-02-19 06:16:17 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS103: Rewrite code to no longer use __guard__
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-06-02 04:51:34 -04:00
|
|
|
const tenMinutes = 10 * 60 * 1000
|
2020-11-25 06:57:25 -05:00
|
|
|
const Metrics = require('@overleaf/metrics')
|
2020-02-19 06:16:18 -05:00
|
|
|
Metrics.initialize('clsi')
|
|
|
|
|
|
|
|
const CompileController = require('./app/js/CompileController')
|
2021-05-13 09:07:54 -04:00
|
|
|
const ContentController = require('./app/js/ContentController')
|
2021-07-12 12:47:21 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-02-19 06:16:18 -05:00
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
logger.initialize('clsi')
|
2020-02-19 06:16:17 -05:00
|
|
|
if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) {
|
2020-02-19 06:16:18 -05:00
|
|
|
logger.initializeErrorReporting(Settings.sentry.dsn)
|
2020-02-19 06:16:17 -05:00
|
|
|
}
|
|
|
|
|
2020-05-07 12:57:35 -04:00
|
|
|
const smokeTest = require('./test/smoke/js/SmokeTests')
|
2020-02-19 06:16:18 -05:00
|
|
|
const ContentTypeMapper = require('./app/js/ContentTypeMapper')
|
|
|
|
const Errors = require('./app/js/Errors')
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
const Path = require('path')
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
Metrics.open_sockets.monitor(logger)
|
|
|
|
Metrics.memory.monitor(logger)
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
const ProjectPersistenceManager = require('./app/js/ProjectPersistenceManager')
|
|
|
|
const OutputCacheManager = require('./app/js/OutputCacheManager')
|
2021-05-13 09:56:15 -04:00
|
|
|
const ContentCacheManager = require('./app/js/ContentCacheManager')
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
require('./app/js/db').sync()
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
const express = require('express')
|
|
|
|
const bodyParser = require('body-parser')
|
|
|
|
const app = express()
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
Metrics.injectMetricsRoute(app)
|
|
|
|
app.use(Metrics.http.monitor(logger))
|
2020-02-19 06:16:17 -05:00
|
|
|
|
|
|
|
// Compile requests can take longer than the default two
|
2020-02-19 06:16:18 -05:00
|
|
|
// minutes (including file download time), so bump up the
|
2020-02-19 06:16:17 -05:00
|
|
|
// timeout a bit.
|
2020-02-19 06:16:18 -05:00
|
|
|
const TIMEOUT = 10 * 60 * 1000
|
2020-08-10 12:01:11 -04:00
|
|
|
app.use(function (req, res, next) {
|
2020-02-19 06:16:18 -05:00
|
|
|
req.setTimeout(TIMEOUT)
|
|
|
|
res.setTimeout(TIMEOUT)
|
|
|
|
res.removeHeader('X-Powered-By')
|
|
|
|
return next()
|
|
|
|
})
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.param('project_id', function (req, res, next, projectId) {
|
2020-06-02 04:51:34 -04:00
|
|
|
if (projectId != null ? projectId.match(/^[a-zA-Z0-9_-]+$/) : undefined) {
|
2020-02-19 06:16:18 -05:00
|
|
|
return next()
|
|
|
|
} else {
|
|
|
|
return next(new Error('invalid project id'))
|
|
|
|
}
|
|
|
|
})
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.param('user_id', function (req, res, next, userId) {
|
2020-06-02 04:51:34 -04:00
|
|
|
if (userId != null ? userId.match(/^[0-9a-f]{24}$/) : undefined) {
|
2020-02-19 06:16:18 -05:00
|
|
|
return next()
|
|
|
|
} else {
|
|
|
|
return next(new Error('invalid user id'))
|
|
|
|
}
|
|
|
|
})
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.param('build_id', function (req, res, next, buildId) {
|
2020-02-19 06:16:18 -05:00
|
|
|
if (
|
2020-06-02 04:51:34 -04:00
|
|
|
buildId != null ? buildId.match(OutputCacheManager.BUILD_REGEX) : undefined
|
2020-02-19 06:16:18 -05:00
|
|
|
) {
|
|
|
|
return next()
|
|
|
|
} else {
|
2020-06-02 04:51:34 -04:00
|
|
|
return next(new Error(`invalid build id ${buildId}`))
|
2020-02-19 06:16:18 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-05-13 09:56:15 -04:00
|
|
|
app.param('contentId', function (req, res, next, contentId) {
|
|
|
|
if (
|
|
|
|
contentId != null
|
|
|
|
? contentId.match(OutputCacheManager.CONTENT_REGEX)
|
|
|
|
: undefined
|
|
|
|
) {
|
|
|
|
return next()
|
|
|
|
} else {
|
|
|
|
return next(new Error(`invalid content id ${contentId}`))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
app.param('hash', function (req, res, next, hash) {
|
|
|
|
if (hash != null ? hash.match(ContentCacheManager.HASH_REGEX) : undefined) {
|
|
|
|
return next()
|
|
|
|
} else {
|
|
|
|
return next(new Error(`invalid hash ${hash}`))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
app.post(
|
|
|
|
'/project/:project_id/compile',
|
|
|
|
bodyParser.json({ limit: Settings.compileSizeLimit }),
|
|
|
|
CompileController.compile
|
|
|
|
)
|
|
|
|
app.post('/project/:project_id/compile/stop', CompileController.stopCompile)
|
|
|
|
app.delete('/project/:project_id', CompileController.clearCache)
|
|
|
|
|
|
|
|
app.get('/project/:project_id/sync/code', CompileController.syncFromCode)
|
|
|
|
app.get('/project/:project_id/sync/pdf', CompileController.syncFromPdf)
|
|
|
|
app.get('/project/:project_id/wordcount', CompileController.wordcount)
|
|
|
|
app.get('/project/:project_id/status', CompileController.status)
|
2021-03-16 06:24:59 -04:00
|
|
|
app.post('/project/:project_id/status', CompileController.status)
|
2020-02-19 06:16:17 -05:00
|
|
|
|
|
|
|
// Per-user containers
|
2020-02-19 06:16:18 -05:00
|
|
|
app.post(
|
|
|
|
'/project/:project_id/user/:user_id/compile',
|
|
|
|
bodyParser.json({ limit: Settings.compileSizeLimit }),
|
|
|
|
CompileController.compile
|
|
|
|
)
|
|
|
|
app.post(
|
|
|
|
'/project/:project_id/user/:user_id/compile/stop',
|
|
|
|
CompileController.stopCompile
|
|
|
|
)
|
|
|
|
app.delete('/project/:project_id/user/:user_id', CompileController.clearCache)
|
|
|
|
|
|
|
|
app.get(
|
|
|
|
'/project/:project_id/user/:user_id/sync/code',
|
|
|
|
CompileController.syncFromCode
|
|
|
|
)
|
|
|
|
app.get(
|
|
|
|
'/project/:project_id/user/:user_id/sync/pdf',
|
|
|
|
CompileController.syncFromPdf
|
|
|
|
)
|
|
|
|
app.get(
|
|
|
|
'/project/:project_id/user/:user_id/wordcount',
|
|
|
|
CompileController.wordcount
|
|
|
|
)
|
|
|
|
|
|
|
|
const ForbidSymlinks = require('./app/js/StaticServerForbidSymlinks')
|
2020-02-19 06:16:17 -05:00
|
|
|
|
|
|
|
// create a static server which does not allow access to any symlinks
|
|
|
|
// avoids possible mismatch of root directory between middleware check
|
|
|
|
// and serving the files
|
2020-12-15 07:03:25 -05:00
|
|
|
const staticCompileServer = ForbidSymlinks(
|
|
|
|
express.static,
|
|
|
|
Settings.path.compilesDir,
|
|
|
|
{
|
|
|
|
setHeaders(res, path, stat) {
|
|
|
|
if (Path.basename(path) === 'output.pdf') {
|
|
|
|
// Calculate an etag in the same way as nginx
|
|
|
|
// https://github.com/tj/send/issues/65
|
|
|
|
const etag = (path, stat) =>
|
|
|
|
`"${Math.ceil(+stat.mtime / 1000).toString(16)}` +
|
|
|
|
'-' +
|
|
|
|
Number(stat.size).toString(16) +
|
|
|
|
'"'
|
|
|
|
res.set('Etag', etag(path, stat))
|
|
|
|
}
|
|
|
|
return res.set('Content-Type', ContentTypeMapper.map(path))
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:16:18 -05:00
|
|
|
}
|
2020-12-15 07:03:25 -05:00
|
|
|
)
|
2020-02-19 06:16:18 -05:00
|
|
|
|
2020-12-15 09:59:05 -05:00
|
|
|
const staticOutputServer = ForbidSymlinks(
|
|
|
|
express.static,
|
|
|
|
Settings.path.outputDir,
|
|
|
|
{
|
|
|
|
setHeaders(res, path, stat) {
|
|
|
|
if (Path.basename(path) === 'output.pdf') {
|
|
|
|
// Calculate an etag in the same way as nginx
|
|
|
|
// https://github.com/tj/send/issues/65
|
|
|
|
const etag = (path, stat) =>
|
|
|
|
`"${Math.ceil(+stat.mtime / 1000).toString(16)}` +
|
|
|
|
'-' +
|
|
|
|
Number(stat.size).toString(16) +
|
|
|
|
'"'
|
|
|
|
res.set('Etag', etag(path, stat))
|
|
|
|
}
|
|
|
|
return res.set('Content-Type', ContentTypeMapper.map(path))
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-12-15 09:59:05 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.get(
|
|
|
|
'/project/:project_id/user/:user_id/build/:build_id/output/*',
|
|
|
|
function (req, res, next) {
|
|
|
|
// for specific build get the path from the OutputCacheManager (e.g. .clsi/buildId)
|
|
|
|
req.url =
|
|
|
|
`/${req.params.project_id}-${req.params.user_id}/` +
|
|
|
|
OutputCacheManager.path(req.params.build_id, `/${req.params[0]}`)
|
2020-12-15 09:59:05 -05:00
|
|
|
return staticOutputServer(req, res, next)
|
2020-08-10 12:01:11 -04:00
|
|
|
}
|
|
|
|
)
|
2020-02-19 06:16:18 -05:00
|
|
|
|
2021-05-13 09:07:54 -04:00
|
|
|
app.get(
|
|
|
|
'/project/:projectId/content/:contentId/:hash',
|
|
|
|
ContentController.getPdfRange
|
|
|
|
)
|
|
|
|
app.get(
|
|
|
|
'/project/:projectId/user/:userId/content/:contentId/:hash',
|
|
|
|
ContentController.getPdfRange
|
|
|
|
)
|
|
|
|
|
2021-07-13 07:04:48 -04:00
|
|
|
app.get(
|
|
|
|
'/project/:project_id/build/:build_id/output/*',
|
|
|
|
function (req, res, next) {
|
|
|
|
// for specific build get the path from the OutputCacheManager (e.g. .clsi/buildId)
|
|
|
|
req.url =
|
|
|
|
`/${req.params.project_id}/` +
|
|
|
|
OutputCacheManager.path(req.params.build_id, `/${req.params[0]}`)
|
|
|
|
return staticOutputServer(req, res, next)
|
|
|
|
}
|
|
|
|
)
|
2020-02-19 06:16:18 -05:00
|
|
|
|
2021-07-13 07:04:48 -04:00
|
|
|
app.get(
|
|
|
|
'/project/:project_id/user/:user_id/output/*',
|
|
|
|
function (req, res, next) {
|
|
|
|
// for specific user get the path to the top level file
|
|
|
|
logger.warn(
|
|
|
|
{ url: req.url },
|
|
|
|
'direct request for file in compile directory'
|
|
|
|
)
|
|
|
|
req.url = `/${req.params.project_id}-${req.params.user_id}/${req.params[0]}`
|
|
|
|
return staticCompileServer(req, res, next)
|
|
|
|
}
|
|
|
|
)
|
2020-02-19 06:16:18 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.get('/project/:project_id/output/*', function (req, res, next) {
|
2021-01-22 06:03:47 -05:00
|
|
|
logger.warn({ url: req.url }, 'direct request for file in compile directory')
|
2020-02-19 06:16:18 -05:00
|
|
|
if (
|
|
|
|
(req.query != null ? req.query.build : undefined) != null &&
|
|
|
|
req.query.build.match(OutputCacheManager.BUILD_REGEX)
|
|
|
|
) {
|
|
|
|
// for specific build get the path from the OutputCacheManager (e.g. .clsi/buildId)
|
|
|
|
req.url =
|
|
|
|
`/${req.params.project_id}/` +
|
|
|
|
OutputCacheManager.path(req.query.build, `/${req.params[0]}`)
|
|
|
|
} else {
|
|
|
|
req.url = `/${req.params.project_id}/${req.params[0]}`
|
|
|
|
}
|
2020-12-15 07:03:25 -05:00
|
|
|
return staticCompileServer(req, res, next)
|
2020-02-19 06:16:18 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.get('/oops', function (req, res, next) {
|
2020-02-19 06:16:18 -05:00
|
|
|
logger.error({ err: 'hello' }, 'test error')
|
|
|
|
return res.send('error\n')
|
|
|
|
})
|
|
|
|
|
2021-01-26 11:35:39 -05:00
|
|
|
app.get('/oops-internal', function (req, res, next) {
|
|
|
|
setTimeout(function () {
|
|
|
|
throw new Error('Test error')
|
|
|
|
}, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
app.get('/status', (req, res, next) => res.send('CLSI is alive\n'))
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-05-11 07:08:13 -04:00
|
|
|
Settings.processTooOld = false
|
2020-04-23 06:32:33 -04:00
|
|
|
if (Settings.processLifespanLimitMs) {
|
|
|
|
Settings.processLifespanLimitMs +=
|
|
|
|
Settings.processLifespanLimitMs * (Math.random() / 10)
|
2020-05-07 12:57:35 -04:00
|
|
|
logger.info(
|
|
|
|
'Lifespan limited to ',
|
|
|
|
Date.now() + Settings.processLifespanLimitMs
|
|
|
|
)
|
2020-04-23 06:32:33 -04:00
|
|
|
|
2020-05-07 12:57:35 -04:00
|
|
|
setTimeout(() => {
|
2020-03-20 09:37:58 -04:00
|
|
|
logger.log('shutting down, process is too old')
|
2020-05-11 07:08:13 -04:00
|
|
|
Settings.processTooOld = true
|
2020-05-07 12:57:35 -04:00
|
|
|
}, Settings.processLifespanLimitMs)
|
2020-03-20 09:37:58 -04:00
|
|
|
}
|
|
|
|
|
2020-06-02 04:51:34 -04:00
|
|
|
function runSmokeTest() {
|
|
|
|
if (Settings.processTooOld) return
|
|
|
|
logger.log('running smoke tests')
|
2021-07-13 07:04:48 -04:00
|
|
|
smokeTest.triggerRun(err => {
|
2020-06-02 04:51:34 -04:00
|
|
|
if (err) logger.error({ err }, 'smoke tests failed')
|
|
|
|
setTimeout(runSmokeTest, 30 * 1000)
|
|
|
|
})
|
|
|
|
}
|
2020-02-19 06:16:17 -05:00
|
|
|
if (Settings.smokeTest) {
|
2020-03-20 09:37:58 -04:00
|
|
|
runSmokeTest()
|
2020-02-19 06:16:17 -05:00
|
|
|
}
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.get('/health_check', function (req, res) {
|
2020-05-11 07:08:13 -04:00
|
|
|
if (Settings.processTooOld) {
|
|
|
|
return res.status(500).json({ processTooOld: true })
|
|
|
|
}
|
2020-05-07 12:57:35 -04:00
|
|
|
smokeTest.sendLastResult(res)
|
2020-02-19 06:16:18 -05:00
|
|
|
})
|
|
|
|
|
2020-05-07 12:57:35 -04:00
|
|
|
app.get('/smoke_test_force', (req, res) => smokeTest.sendNewResult(res))
|
2020-02-19 06:16:18 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
app.use(function (error, req, res, next) {
|
2020-02-19 06:16:18 -05:00
|
|
|
if (error instanceof Errors.NotFoundError) {
|
2020-06-15 06:06:54 -04:00
|
|
|
logger.log({ err: error, url: req.url }, 'not found error')
|
2020-02-19 06:16:18 -05:00
|
|
|
return res.sendStatus(404)
|
2020-06-11 05:54:26 -04:00
|
|
|
} else if (error.code === 'EPIPE') {
|
|
|
|
// inspect container returns EPIPE when shutting down
|
|
|
|
return res.sendStatus(503) // send 503 Unavailable response
|
2020-02-19 06:16:18 -05:00
|
|
|
} else {
|
|
|
|
logger.error({ err: error, url: req.url }, 'server error')
|
|
|
|
return res.sendStatus((error != null ? error.statusCode : undefined) || 500)
|
|
|
|
}
|
|
|
|
})
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
const net = require('net')
|
|
|
|
const os = require('os')
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
let STATE = 'up'
|
2020-02-19 06:16:17 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
const loadTcpServer = net.createServer(function (socket) {
|
|
|
|
socket.on('error', function (err) {
|
2020-02-19 06:16:18 -05:00
|
|
|
if (err.code === 'ECONNRESET') {
|
|
|
|
// this always comes up, we don't know why
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logger.err({ err }, 'error with socket on load check')
|
|
|
|
return socket.destroy()
|
|
|
|
})
|
|
|
|
|
|
|
|
if (STATE === 'up' && Settings.internal.load_balancer_agent.report_load) {
|
|
|
|
let availableWorkingCpus
|
|
|
|
const currentLoad = os.loadavg()[0]
|
|
|
|
|
|
|
|
// staging clis's have 1 cpu core only
|
|
|
|
if (os.cpus().length === 1) {
|
|
|
|
availableWorkingCpus = 1
|
|
|
|
} else {
|
|
|
|
availableWorkingCpus = os.cpus().length - 1
|
|
|
|
}
|
|
|
|
|
|
|
|
const freeLoad = availableWorkingCpus - currentLoad
|
|
|
|
let freeLoadPercentage = Math.round((freeLoad / availableWorkingCpus) * 100)
|
|
|
|
if (freeLoadPercentage <= 0) {
|
2021-08-26 04:05:42 -04:00
|
|
|
freeLoadPercentage = 0 // when its 0 the server is set to drain and will move projects to different servers
|
2020-02-19 06:16:18 -05:00
|
|
|
}
|
|
|
|
socket.write(`up, ${freeLoadPercentage}%\n`, 'ASCII')
|
|
|
|
return socket.end()
|
|
|
|
} else {
|
|
|
|
socket.write(`${STATE}\n`, 'ASCII')
|
|
|
|
return socket.end()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const loadHttpServer = express()
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
loadHttpServer.post('/state/up', function (req, res, next) {
|
2020-02-19 06:16:18 -05:00
|
|
|
STATE = 'up'
|
|
|
|
logger.info('getting message to set server to down')
|
|
|
|
return res.sendStatus(204)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
loadHttpServer.post('/state/down', function (req, res, next) {
|
2020-02-19 06:16:18 -05:00
|
|
|
STATE = 'down'
|
|
|
|
logger.info('getting message to set server to down')
|
|
|
|
return res.sendStatus(204)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
loadHttpServer.post('/state/maint', function (req, res, next) {
|
2020-02-19 06:16:18 -05:00
|
|
|
STATE = 'maint'
|
|
|
|
logger.info('getting message to set server to maint')
|
|
|
|
return res.sendStatus(204)
|
|
|
|
})
|
|
|
|
|
|
|
|
const port =
|
|
|
|
__guard__(
|
|
|
|
Settings.internal != null ? Settings.internal.clsi : undefined,
|
2021-07-13 07:04:48 -04:00
|
|
|
x => x.port
|
2020-02-19 06:16:18 -05:00
|
|
|
) || 3013
|
|
|
|
const host =
|
|
|
|
__guard__(
|
|
|
|
Settings.internal != null ? Settings.internal.clsi : undefined,
|
2021-07-13 07:04:48 -04:00
|
|
|
x1 => x1.host
|
2020-02-19 06:16:18 -05:00
|
|
|
) || 'localhost'
|
|
|
|
|
2020-06-02 04:51:34 -04:00
|
|
|
const loadTcpPort = Settings.internal.load_balancer_agent.load_port
|
|
|
|
const loadHttpPort = Settings.internal.load_balancer_agent.local_port
|
2020-02-19 06:16:18 -05:00
|
|
|
|
|
|
|
if (!module.parent) {
|
|
|
|
// Called directly
|
2021-01-26 09:08:29 -05:00
|
|
|
|
|
|
|
// handle uncaught exceptions when running in production
|
|
|
|
if (Settings.catchErrors) {
|
|
|
|
process.removeAllListeners('uncaughtException')
|
2021-07-13 07:04:48 -04:00
|
|
|
process.on('uncaughtException', error =>
|
2021-01-26 09:08:29 -05:00
|
|
|
logger.error({ err: error }, 'uncaughtException')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-13 07:04:48 -04:00
|
|
|
app.listen(port, host, error => {
|
2020-06-02 04:51:34 -04:00
|
|
|
if (error) {
|
|
|
|
logger.fatal({ error }, `Error starting CLSI on ${host}:${port}`)
|
|
|
|
} else {
|
|
|
|
logger.info(`CLSI starting up, listening on ${host}:${port}`)
|
|
|
|
}
|
|
|
|
})
|
2020-02-19 06:16:18 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
loadTcpServer.listen(loadTcpPort, host, function (error) {
|
2020-02-19 06:16:18 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2020-06-02 04:51:34 -04:00
|
|
|
return logger.info(`Load tcp agent listening on load port ${loadTcpPort}`)
|
2020-02-19 06:16:18 -05:00
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
loadHttpServer.listen(loadHttpPort, host, function (error) {
|
2020-02-19 06:16:18 -05:00
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2020-06-02 04:51:34 -04:00
|
|
|
return logger.info(`Load http agent listening on load port ${loadHttpPort}`)
|
2020-02-19 06:16:18 -05:00
|
|
|
})
|
2020-02-19 06:16:17 -05:00
|
|
|
}
|
2018-02-16 06:36:32 -05:00
|
|
|
|
2020-02-19 06:16:18 -05:00
|
|
|
module.exports = app
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2020-05-11 05:29:16 -04:00
|
|
|
setInterval(() => {
|
2021-06-01 10:51:09 -04:00
|
|
|
ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
|
|
|
ProjectPersistenceManager.clearExpiredProjects()
|
|
|
|
})
|
2020-06-02 04:51:34 -04:00
|
|
|
}, tenMinutes)
|
2016-04-08 08:31:23 -04:00
|
|
|
|
2020-02-19 06:16:17 -05:00
|
|
|
function __guard__(value, transform) {
|
2020-02-19 06:16:18 -05:00
|
|
|
return typeof value !== 'undefined' && value !== null
|
|
|
|
? transform(value)
|
|
|
|
: undefined
|
|
|
|
}
|