Skip to content

Commit

Permalink
Add tripwire module for restarting process if memory limit exeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
tormozz48 committed Apr 11, 2015
1 parent 5576a0c commit f70f476
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ cache

config/_bse.json
config/_config.json
config/_tripwire.json
26 changes: 15 additions & 11 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var fs = require('fs'),
path = require('path'),
inherit = require('inherit'),
SnapshotMaster = require('../lib/master/index'),
fsExtra = require('fs-extra'),
bseAdmin = require('bse-admin'),
Tripwire = require('memory-tripwire'),
logger = require('bem-site-logger').createLogger(module),
SnapshotMaster = require('../lib/master/index'),

DataBuilder = inherit(SnapshotMaster, {

Expand Down Expand Up @@ -35,15 +38,16 @@ var fs = require('fs'),
.then(function () { this['setIdle'](); }, this)
.fail(function () { this['setIdle'](); }, this);
}
});
}),
tripWireConfig = fsExtra.readJSONFileSync('./config/_tripwire.json'),
appConfig = fsExtra.readJSONFileSync('./config/_config.json'),
tripwire = new Tripwire(tripWireConfig),
builder = new DataBuilder(appConfig);

fs.readFile('./config/_config.json', { encoding: 'utf-8' }, function (error, config) {
if (error) {
logger.error('Can\'t read configuration file for snapshot-master tool');
throw error;
}
var builder = new DataBuilder(JSON.parse(config));
builder.loadConfig(function () {
builder.start();
});
tripwire.start();
tripwire.on('bomb', function () {
logger.warn('||| --- MEMORY LIMIT EXCEED. PROCESS WILL BE RESTARTED --- ||| ');
});
builder.loadConfig(function () {
builder.start();
});
8 changes: 8 additions & 0 deletions config/tripwire.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"warning": "900mb",
"critical": "1000mb",
"interval": "1s",
"cycle": 3,
"exitTime": "5s",
"disconnectTime": "3s"
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"fstream": "^1.0.x",
"inherit": "^2.2.x",
"lodash": "^3.1.x",
"memory-tripwire": "^1.0.0",
"moment": "^2.9.0",
"tar": "^2.0.x",
"trtd": "^0.0.x",
Expand All @@ -42,9 +43,10 @@
"jscs": "^1.11.x"
},
"scripts": {
"_app_config": "cp config/config.json config/_config.json",
"_bse_config": "cp config/bse.json config/_bse.json",
"config": "npm run _app_config && npm run _bse_config",
"_app_config": "cp -i config/config.json config/_config.json",
"_bse_config": "cp -i config/bse.json config/_bse.json",
"_tripwire_config": "cp -i config/tripwire.json config/_tripwire.json",
"config": "npm run _app_config && npm run _bse_config && npm run _tripwire_config",
"mocha": "NODE_ENV=testing node_modules/.bin/mocha",
"istanbul": "istanbul cover ./node_modules/mocha/bin/_mocha",
"codestyle": "node_modules/.bin/jshint . && node_modules/.bin/jscs -c .jscs.js .",
Expand Down

0 comments on commit f70f476

Please sign in to comment.