1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

added support for pid file

This commit is contained in:
Massimo Candela
2019-12-11 15:49:27 +01:00
parent f48cffcf4d
commit 264a7ca7e8
6 changed files with 37 additions and 4 deletions

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@ bin/
build/
logs/
.DS_Store
bgpalerter.pid

View File

@@ -178,3 +178,5 @@ uptimeMonitor:
port: 8011
############################
pidFile: bgpalerter.pid

View File

@@ -129,7 +129,8 @@ let config = {
active: false,
useStatusCodes: true,
port: 8011
}
},
pidFile: "bgpalerter.pid"
};

View File

@@ -33,6 +33,7 @@
import Consumer from "./consumer";
import ConnectorFactory from "./connectorFactory";
import cluster from "cluster";
import fs from "fs";
export default class Worker {
constructor(configFile) {
@@ -63,10 +64,20 @@ export default class Worker {
}
master = (worker) => {
console.log("BGPalerter, version:", this.version, "environment:", this.config.environment);
console.log("Loaded config:", this.configFile);
// Write pid on a file
if (this.config.pidFile) {
try {
fs.writeFileSync(this.config.pidFile, process.pid);
} catch (error) {
this.logger.log({
level: 'error',
message: "Cannot write pid file: " + error
});
}
}
const connectorFactory = new ConnectorFactory();

View File

@@ -77,7 +77,8 @@ describe("Composition", function() {
"monitoredPrefixesFiles",
"logging",
"checkForUpdatesAtBoot",
"uptimeMonitor"
"uptimeMonitor",
"pidFile"
]);
expect(config.connectors[0]).to.have
.property('class')
@@ -326,6 +327,21 @@ describe("Composition", function() {
done();
});
});
it("write pid file", function (done) {
const file = config.pidFile;
expect("bgpalerter.pid").to.equal(file);
if (file) {
readLastLines
.read(file, 1)
.then((line) => {
expect(parseInt(line)).to.equal(process.pid);
done();
});
}
});
});
});

View File

@@ -66,4 +66,6 @@ checkForUpdatesAtBoot: true
uptimeMonitor:
active: true
useStatusCodes: true
port: 8011
port: 8011
pidFile: bgpalerter.pid