srap/bin/run

43 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-03-18 23:49:16 +01:00
#!/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");
2022-03-04 01:47:44 +01:00
const express = require("express");
2021-03-18 23:49:16 +01:00
const createKernel = require("../src/kernel");
let argv = yargs.argv;
let configurationPath = argv._[0];
2022-03-04 03:18:21 +01:00
let listenHost = argv.listenHost ?? "127.0.0.1";
let listenPort = argv.listenPort ?? 3131;
2021-03-18 23:49:16 +01:00
2022-03-04 03:18:21 +01:00
let absoluteConfigurationPath = path.join(process.cwd(), configurationPath);
2021-03-18 23:49:16 +01:00
let configuration = require(absoluteConfigurationPath);
return Promise.try(() => {
return createKernel(configuration);
}).then((kernel) => {
kernel.run();
2022-03-04 01:47:44 +01:00
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);
});
});
2022-03-04 03:18:21 +01:00
metricsApp.listen({ host: listenHost, port: listenPort }, () => {
console.log(`Metrics server listening on port ${listenPort}, host ${listenHost}`);
});
2021-03-18 23:49:16 +01:00
});