mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-22 00:40:23 +00:00
testing update, server now runnable from test and capable to receive die command
This commit is contained in:
parent
4105a2f41d
commit
6f6c0e9166
5 changed files with 43 additions and 12 deletions
|
|
@ -240,8 +240,8 @@ function loadEventModules(args, answHandler) {
|
|||
function shutDown() {
|
||||
log.print('EN', 'Shutting down Poller and DB Link');
|
||||
isRunning = false;
|
||||
poller.send('cmd|shutdown');
|
||||
db.shutDown();
|
||||
if(poller) poller.send('cmd|shutdown');
|
||||
if(db) db.shutDown();
|
||||
}
|
||||
|
||||
exports.init = init;
|
||||
|
|
|
|||
|
|
@ -28,10 +28,13 @@ exports.error = function(module, err) {
|
|||
var e = new Error();
|
||||
if(module) console.error(ts + module + ' | ERROR AND BAD HANDLING: ' + err + '\n' + e.stack);
|
||||
else console.error(ts + '!N/A! | ERROR, BAD HANDLING AND NO MODULE NAME: ' + err + '\n' + e.stack);
|
||||
} else {
|
||||
} else if(err) {
|
||||
if(err.addInfo) ai = ' (' + err.addInfo + ')';
|
||||
if(!err.message) err.message = 'UNKNOWN REASON!\n' + err.stack;
|
||||
if(module) console.error(ts + module + ' | ERROR'+ai+': ' + err.message);
|
||||
else console.error(ts + '!N/A! | ERROR AND NO MODULE NAME'+ai+': ' + err.message + '\n' + err.stack);
|
||||
} else {
|
||||
var e = new Error('Unexpected error');
|
||||
console.error(e.message + ': \n' + e.stack);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
21
js/server.js
21
js/server.js
|
|
@ -22,6 +22,7 @@ dog's back.
|
|||
>
|
||||
> ## This is an H2 in a blockquote
|
||||
*/
|
||||
|
||||
var http_listener = require('./http_listener'),
|
||||
db = require('./db_interface'),
|
||||
engine = require('./engine'),
|
||||
|
|
@ -29,6 +30,9 @@ var http_listener = require('./http_listener'),
|
|||
log = require('./logging'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
procCmds = {
|
||||
'die': function() { shutDown(); }
|
||||
},
|
||||
objCmds = {
|
||||
'loadrules': mm.loadRulesFile,
|
||||
'loadaction': mm.loadActionModule,
|
||||
|
|
@ -53,10 +57,14 @@ function handleAdminCommands(args, answHandler) {
|
|||
}
|
||||
|
||||
function shutDown(args, answHandler) {
|
||||
answHandler.answerSuccess('Goodbye!');
|
||||
if(answHandler) answHandler.answerSuccess('Goodbye!');
|
||||
log.print('RS', 'Received shut down command!');
|
||||
engine.shutDown();
|
||||
http_listener.shutDown();
|
||||
if(engine && typeof engine.shutDown === 'function') engine.shutDown();
|
||||
else {
|
||||
console.error(typeof engine.shutDown);
|
||||
console.error('no function!');
|
||||
}
|
||||
if(http_listener) http_listener.shutDown();
|
||||
}
|
||||
|
||||
fs.readFile(path.resolve(__dirname, '..', 'config', 'config.json'), 'utf8', function (err, data) {
|
||||
|
|
@ -78,4 +86,9 @@ fs.readFile(path.resolve(__dirname, '..', 'config', 'config.json'), 'utf8', func
|
|||
log.print('RS', 'Initialzing module manager');
|
||||
mm.init(db, engine.loadActionModule, engine.loadRule);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
process.on('message', function(cmd) {
|
||||
if(typeof procCmds[cmd] === 'function') procCmds[cmd]();
|
||||
else console.error('err with command');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
#!/bin/bash
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
node $DIR/js/webapi_eca_server > $DIR/server.log 2>&1 &
|
||||
node $DIR/js/server > $DIR/server.log 2>&1 &
|
||||
|
|
|
|||
|
|
@ -1,12 +1,27 @@
|
|||
exports.setUp = function() {
|
||||
// this.srv = require('../js/webapi_eca_server.js');
|
||||
var path = require('path');
|
||||
//FIXME handle EADDR in use!
|
||||
exports.setUp = function(cb) {
|
||||
this.srv = require('child_process').fork(path.resolve(__dirname, '..', 'js', 'server'));
|
||||
cb();
|
||||
};
|
||||
|
||||
exports.testUnit_SRV = function(test){
|
||||
console.log(this.srv);
|
||||
test.ok(true, "SRV");
|
||||
setTimeout(
|
||||
function() {
|
||||
|
||||
test.ok(true, "SRV");
|
||||
test.done();
|
||||
}
|
||||
, 2000);
|
||||
};
|
||||
exports.tearDown = function(cb) {
|
||||
console.log('this.srv: ');
|
||||
// console.log(global.srv);
|
||||
this.srv.send('die');
|
||||
this.srv = null;
|
||||
cb();
|
||||
};
|
||||
|
||||
// var http_listener = require('./http_listener'),
|
||||
// db = require('./db_interface'),
|
||||
// engine = require('./engine'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue