2019-02-19 09:51:34 -05:00
|
|
|
metrics = require("metrics-sharelatex")
|
|
|
|
metrics.initialize(process.env['METRICS_APP_NAME'] or "web")
|
2014-02-12 05:23:40 -05:00
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
logger = require 'logger-sharelatex'
|
2019-03-13 12:37:50 -04:00
|
|
|
logger.initialize(process.env['METRICS_APP_NAME'] or "web")
|
2014-02-12 05:23:40 -05:00
|
|
|
logger.logger.serializers.user = require("./app/js/infrastructure/LoggerSerializers").user
|
2018-03-09 06:05:17 -05:00
|
|
|
logger.logger.serializers.docs = require("./app/js/infrastructure/LoggerSerializers").docs
|
|
|
|
logger.logger.serializers.files = require("./app/js/infrastructure/LoggerSerializers").files
|
2014-02-12 05:23:40 -05:00
|
|
|
logger.logger.serializers.project = require("./app/js/infrastructure/LoggerSerializers").project
|
2015-12-08 07:14:40 -05:00
|
|
|
if Settings.sentry?.dsn?
|
|
|
|
logger.initializeErrorReporting(Settings.sentry.dsn)
|
|
|
|
|
2015-12-03 05:52:06 -05:00
|
|
|
metrics.memory.monitor(logger)
|
2014-02-12 05:23:40 -05:00
|
|
|
Server = require("./app/js/infrastructure/Server")
|
|
|
|
|
|
|
|
argv = require("optimist")
|
|
|
|
.options("user", {alias : "u", description : "Run the server with permissions of the specified user"})
|
|
|
|
.options("group", {alias : "g", description : "Run the server with permissions of the specified group"})
|
|
|
|
.usage("Usage: $0")
|
|
|
|
.argv
|
|
|
|
|
|
|
|
if Settings.catchErrors
|
|
|
|
process.removeAllListeners "uncaughtException"
|
|
|
|
process.on "uncaughtException", (error) ->
|
|
|
|
logger.error err: error, "uncaughtException"
|
|
|
|
|
|
|
|
port = Settings.port or Settings.internal?.web?.port or 3000
|
2014-09-02 07:00:33 -04:00
|
|
|
host = Settings.internal.web.host or "localhost"
|
2018-12-13 04:07:55 -05:00
|
|
|
if !module.parent # Called directly
|
|
|
|
Server.server.listen port, host, ->
|
|
|
|
logger.info "web starting up, listening on #{host}:#{port}"
|
|
|
|
logger.info("#{require('http').globalAgent.maxSockets} sockets enabled")
|
|
|
|
if argv.user
|
|
|
|
process.setuid argv.user
|
|
|
|
logger.info "Running as user: #{argv.user}"
|
|
|
|
if argv.group
|
|
|
|
process.setgid argv.group
|
|
|
|
logger.info "Running as group: #{argv.group}"
|
|
|
|
|
|
|
|
module.exports = Server.server
|
2019-02-19 10:40:19 -05:00
|
|
|
|