fxa-auth-server/bin/key_server.js

75 строки
1.7 KiB
JavaScript
Исходник Обычный вид История

#!/usr/bin/env node
2013-07-26 05:46:16 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var fs = require('fs')
var config = require('../config').root()
function main() {
var log = require('../log')(config)
// memory monitor
var MemoryMonitor = require('../memory_monitor')
var memoryMonitor = new MemoryMonitor()
memoryMonitor.on(
'mem',
function (usage) {
log.trace(
{
op: 'stat',
stat: 'mem',
rss: usage.rss,
heapTotal: usage.heapTotal,
heapUsed: usage.heapUsed
}
)
}
)
memoryMonitor.start()
2013-07-27 04:00:09 +04:00
// databases
2013-10-27 06:02:54 +04:00
var DB = require('../db/heap')(log)
var db = new DB()
2013-07-27 04:00:09 +04:00
// TODO: send to the SMTP server directly. In the future this may change
// to another process that we send an http request to.
2013-08-28 05:27:31 +04:00
var mailer = require('../mailer')(config.smtp, log)
2013-07-27 04:00:09 +04:00
// server public key
2013-08-28 21:57:54 +04:00
var serverPublicKey = JSON.parse(fs.readFileSync(config.publicKeyFile))
//signer compute-cluster
var CC = require('compute-cluster')
var signer = new CC({ module: __dirname + '/signer.js' })
2013-10-27 06:02:54 +04:00
var routes = require('../routes')(log, serverPublicKey, signer, db, mailer, config)
var Server = require('../server')
2013-10-26 04:49:49 +04:00
var server = Server.create(log, config, routes, db)
server.start(
function () {
2013-07-26 23:34:15 +04:00
log.info('running on ' + server.info.uri)
}
)
process.on(
'SIGINT',
function () {
2013-07-26 23:34:15 +04:00
memoryMonitor.stop()
server.stop(
function () {
process.exit()
}
)
}
)
}
if (!fs.existsSync(config.publicKeyFile)) {
require('../scripts/gen_keys')(main)
}
else {
main()
}