Build script

A build process that generates a package with single executable for each
component.
This commit is contained in:
Zaid Abdulla committed 2019-01-04 01:13:47 -08:00
1 parent 819e8a52a3
commit 0b59811924
23 files changed
+734 -688

No files matched your search

+112 -6
View File
@@ -1,9 +1,115 @@
#!/usr/bin/env node
var path = require('path');
var fs = require('fs');
"use strict";
const path = require("path");
const fs = require("fs");
var dir = path.resolve(path.dirname(fs.realpathSync(__filename)), '..');
process.chdir(dir);
process.chdir(path.resolve(path.dirname(fs.realpathSync(__filename)), ".."));
var cluster = require(path.resolve(dir, 'lib/cluster'));
cluster.start('cwmp');
const config = require("../lib/config");
const logger = require("../lib/logger");
const cluster = require("../lib/cluster");
const server = require("../lib/server");
const cwmp = require("../lib/cwmp");
const db = require("../lib/db");
const extensions = require("../lib/extensions");
const cache = require("../lib/cache");
const VERSION = require("../package.json").version;
logger.init("cwmp", VERSION);
const SERVICE_ADDRESS = config.get("CWMP_INTERFACE");
const SERVICE_PORT = config.get("CWMP_PORT");
function exitWorkerGracefully() {
db.disconnect();
cache.disconnect();
extensions.killAll();
cluster.worker.disconnect();
}
function exitWorkerUngracefully() {
extensions.killAll(() => {
process.exit(1);
});
}
if (!cluster.worker) {
const WORKER_COUNT = config.get("CWMP_WORKER_PROCESSES");
logger.info({
message: `genieacs-cwmp starting`,
pid: process.pid,
version: VERSION
});
cluster.start(WORKER_COUNT, SERVICE_PORT, SERVICE_ADDRESS);
process.on("SIGINT", () => {
logger.info({
message: "Received signal SIGINT, exiting",
pid: process.pid
});
cluster.stop();
});
process.on("SIGTERM", () => {
logger.info({
message: "Received signal SIGTERM, exiting",
pid: process.pid
});
cluster.stop();
});
} else {
let ssl;
if (config.get("CWMP_SSL")) {
ssl = {
key: path.resolve(config.get("CONFIG_DIR"), "cwmp.key"),
cert: path.resolve(config.get("CONFIG_DIR"), "cwmp.crt"),
ca: path.resolve(config.get("CONFIG_DIR"), "cwmp.ca-bundle")
};
}
process.on("uncaughtException", err => {
if (err.code === "ERR_IPC_DISCONNECTED") return;
logger.error({
message: "Uncaught exception",
exception: err,
pid: process.pid
});
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
process.on("SIGINT", () => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
process.on("SIGTERM", () => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
db.connect(err => {
if (err) throw err;
cache.connect(err => {
if (err) throw err;
server.start(
SERVICE_PORT,
SERVICE_ADDRESS,
ssl,
cwmp.listener,
cwmp.onConnection
);
});
});
}