2013-07-24 22:03:57 +04:00
|
|
|
#!/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/. */
|
|
|
|
|
2013-07-26 00:18:19 +04:00
|
|
|
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()
|
2013-09-17 22:07:39 +04:00
|
|
|
memoryMonitor.on(
|
|
|
|
'mem',
|
|
|
|
function (usage) {
|
|
|
|
log.trace(
|
|
|
|
{
|
|
|
|
op: 'stat',
|
|
|
|
stat: 'mem',
|
|
|
|
rss: usage.rss,
|
|
|
|
heapTotal: usage.heapTotal,
|
|
|
|
heapUsed: usage.heapUsed
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2013-07-26 00:18:19 +04:00
|
|
|
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
|
|
|
|
2013-07-29 23:11:02 +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
|
|
|
|
2013-07-26 00:18:19 +04:00
|
|
|
// server public key
|
2013-08-28 21:57:54 +04:00
|
|
|
var serverPublicKey = JSON.parse(fs.readFileSync(config.publicKeyFile))
|
2013-07-26 00:18:19 +04:00
|
|
|
|
|
|
|
//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)
|
2013-07-26 00:18:19 +04:00
|
|
|
var Server = require('../server')
|
2013-10-26 04:49:49 +04:00
|
|
|
var server = Server.create(log, config, routes, db)
|
2013-07-26 00:18:19 +04:00
|
|
|
|
|
|
|
server.start(
|
|
|
|
function () {
|
2013-07-26 23:34:15 +04:00
|
|
|
log.info('running on ' + server.info.uri)
|
2013-07-26 00:18:19 +04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
process.on(
|
|
|
|
'SIGINT',
|
|
|
|
function () {
|
2013-07-26 23:34:15 +04:00
|
|
|
memoryMonitor.stop()
|
2013-07-26 00:18:19 +04:00
|
|
|
server.stop(
|
|
|
|
function () {
|
|
|
|
process.exit()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fs.existsSync(config.publicKeyFile)) {
|
|
|
|
require('../scripts/gen_keys')(main)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
main()
|
|
|
|
}
|