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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ bin/
|
||||
build/
|
||||
logs/
|
||||
.DS_Store
|
||||
bgpalerter.pid
|
||||
|
@@ -178,3 +178,5 @@ uptimeMonitor:
|
||||
port: 8011
|
||||
|
||||
############################
|
||||
|
||||
pidFile: bgpalerter.pid
|
@@ -129,7 +129,8 @@ let config = {
|
||||
active: false,
|
||||
useStatusCodes: true,
|
||||
port: 8011
|
||||
}
|
||||
},
|
||||
pidFile: "bgpalerter.pid"
|
||||
};
|
||||
|
||||
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@@ -66,4 +66,6 @@ checkForUpdatesAtBoot: true
|
||||
uptimeMonitor:
|
||||
active: true
|
||||
useStatusCodes: true
|
||||
port: 8011
|
||||
port: 8011
|
||||
|
||||
pidFile: bgpalerter.pid
|
Reference in New Issue
Block a user