Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Node-DC-EIS-cluster/automation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

/*
Copyright (c) 2017 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

var _spawn = require('cross-spawn');
var Promise = require('bluebird');
var _waitOn = Promise.promisify(require('wait-on'));

var _config = require('./config/configuration.js');

var env = process.env;

function npmRun(args) {
return _spawn(env.npm_node_execpath,
[env.npm_execpath, '-s', 'run'].concat(args),
{stdio: 'inherit'});
}

function npmRunSync(args) {
return _spawn.sync(env.npm_node_execpath,
[env.npm_execpath, '-s', 'run'].concat(args),
{ stdio: 'inherit' });
}


children = [];

function killChildren() {
children.forEach(function(cc) {
cc.kill();
});
}

var mongoPort = '27017';
if(_config.db_url) {
var match = _config.db_url.match(new RegExp('mongodb://([^/]+)/'));
if(match.length > 1 && match[1]) {
mongoPort = match[1];
}
}

var npm_event = env.npm_lifecycle_event.split(':');

var node_env = (npm_event.length > 1 && npm_event[1]) ? npm_event[1] : 'prod';

children.push(npmRun('mongodb'));
_waitOn({
resources: [
'tcp:' + mongoPort
]
}).then(function() {
children.push(npmRun('server:' + node_env));
return _waitOn({
resources: [
'http://' + (_config.app_host || 'localhost') + ':' +
(_config.app_port || '9000') +'/'
]
});
}).then(function() {
npmRunSync('runspec');
}).catch(function(err) {
killChildren();
console.error(err);
process.exit(1);
}).then(function() {
killChildren();
process.exit(0);
});
17 changes: 14 additions & 3 deletions Node-DC-EIS-cluster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
"url": "git://github.com/Node-DC/Node-DC-EIS.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server-cluster.js"
"server": "npm -s run server:prod",
"server:prod": "cross-env NODE_ENV=production node server-cluster.js",
"server:dev": "cross-env NODE_ENV=development node server-cluster.js",
"mongodb": "mkdirp ../mongodata && numactl --interleave=all mongod --dbpath ../mongodata",
"runspec": "cd ../Node-DC-EIS-client && python2 runspec.py -f config.json",
"start": "npm -s run start:prod",
"start:prod": "node automation.js",
"start:dev": "node automation.js"
},
"author": "Uttam C Pawar <uttam.c.pawar@intel.com>",
"contributors": [
Expand All @@ -19,11 +25,16 @@
"license": "Apache-2.0",
"dependencies": {
"async": "^2.0.1",
"bluebird": "^3.5.1",
"body-parser": "^1.15.0",
"cross-env": "^5.1.0",
"cross-spawn": "^5.1.0",
"express": "^4.13.3",
"lru-cache": "^4.0.1",
"mkdirp": "^0.5.1",
"mongoose": "4.4.12",
"pug": "^2.0.0-rc.1"
"pug": "^2.0.0-rc.1",
"wait-on": "^2.0.2"
},
"devDependencies": {},
"keywords": [
Expand Down