You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
srap/bin/run

43 lines
1.2 KiB
Plaintext

4 years ago
#!/usr/bin/env node
"use strict";
// FIXME: Safe shutdown on ctrl+C
// FIXME: Somehow automatically detect whether other kernels are running on the system, and automatically clear locks when that is not the case?
const Promise = require("bluebird");
const yargs = require("yargs");
const path = require("path");
3 years ago
const express = require("express");
4 years ago
const createKernel = require("../src/kernel");
let argv = yargs.argv;
let configurationPath = argv._[0];
let listenHost = argv.listenHost ?? "127.0.0.1";
let listenPort = argv.listenPort ?? 3131;
4 years ago
let absoluteConfigurationPath = path.resolve(process.cwd(), configurationPath);
4 years ago
let configuration = require(absoluteConfigurationPath);
return Promise.try(() => {
return createKernel(configuration);
}).then((kernel) => {
kernel.run();
3 years ago
let metricsApp = express();
metricsApp.get("/metrics", (req, res) => {
return Promise.try(() => {
return kernel.getMetrics();
}).then(({ contentType, metrics }) => {
res.set("Content-Type", contentType);
res.send(metrics);
});
});
metricsApp.listen({ host: listenHost, port: listenPort }, () => {
console.log(`Metrics server listening on port ${listenPort}, host ${listenHost}`);
});
4 years ago
});