Skip to content

Commit

Permalink
new project
Browse files Browse the repository at this point in the history
  • Loading branch information
bboalimoe committed May 7, 2015
0 parents commit 2569015
Show file tree
Hide file tree
Showing 4,369 changed files with 566,255 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .foreverignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea


2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea

7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM google/nodejs-runtime
ADD install.sh /app
WORKDIR /app
RUN bash install.sh



2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# senz-log-hook
# lots of modules
42 changes: 42 additions & 0 deletions cloud/files/error
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.js:338
throw err;
^
Error: Cannot find module './cloud/rabbit_lib/publisher'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/zhanghengyang/WebstormProjects/senz.middleware.rabbitmq.type/cloud/main.js:1:79)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
module.js:338
throw err;
^
Error: Cannot find module './cloud/rabbit_lib/publisher'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/zhanghengyang/WebstormProjects/senz.middleware.rabbitmq.type/cloud/main.js:1:79)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
module.js:338
throw err;
^
Error: Cannot find module './cloud/rabbit_lib/publisher'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/zhanghengyang/WebstormProjects/senz.middleware.rabbitmq.type/cloud/main.js:1:79)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
Empty file added cloud/files/logfile
Empty file.
Empty file added cloud/files/output
Empty file.
94 changes: 94 additions & 0 deletions cloud/forever_monitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Created by zhanghengyang on 15/5/4.
*/
var logger = require("./utils/logger");
var forever = require("forever-monitor");

var configuration = {
//
// Basic configuration options
//
'silent': false, // Silences the output from stdout and stderr in the parent process
'uid': 'senz-log-hooker-UID', // Custom uid for this forever process. (default: autogen)
'pidFile': '../senz-log.pid', // Path to put pid information for the process(es) started
'max': 3, // Sets the maximum number of times a given script should run
'killTree': true, // Kills the entire child process tree on `exit`

//
// These options control how quickly forever restarts a child process
// as well as when to kill a "spinning" process
//
'minUptime': 2000, // Minimum time a child process has to be up. Forever will 'exit' otherwise.
'spinSleepTime': 1000, // Interval between restarts if a child is spinning (i.e. alive < minUptime).

//
// Command to spawn as well as options and other vars
// (env, cwd, etc) to pass along
//
//'command': 'perl', // Binary to run (default: 'node')
//'args': ['foo','bar'], // Additional arguments to pass to the script,
//'sourceDir': 'script/path',// Directory that the source script is in

//
// Options for restarting on watched files.
//
'watch': true, // Value indicating if we should watch files.
'watchIgnoreDotFiles': true, // Whether to ignore file starting with a '.'
'watchIgnorePatterns': null, // Ignore patterns to use when watching files.
'watchDirectory': "./", // Top-level directory to watch from.

//
// All or nothing options passed along to `child_process.spawn`.
//
//'spawnWith': {
// customFds: [-1, -1, -1], // that forever spawns.
// setsid: false,
// uid: 0, // Custom UID
// gid: 0 // Custom GID
//},

//
// More specific options to pass along to `child_process.spawn` which
// will override anything passed to the `spawnWith` option
//
//'env': { 'ADDITIONAL': 'CHILD ENV VARS' },
//'cwd': '/path/to/child/working/directory',

//
// Log files and associated logging options for this instance
//
'logFile': './files/logfile', // Path to log output from forever process (when daemonized)
'outFile': './files/output', // Path to log output from child stdout
'errFile': './files/error', // Path to log output from child stderr

//
// ### function parseCommand (command, args)
// #### @command {String} Command string to parse
// #### @args {Array} Additional default arguments
//
// Returns the `command` and the `args` parsed from
// any command. Use this to modify the default parsing
// done by 'forever-monitor' around spaces.
//
'parser': function (command, args) {
return {
command: command,
args: args
};
}
}

var child = new (forever.Monitor)("./main.js",configuration);

child.on('watch:restart', function(info) {
logger.error('Restaring script because ' + info.file + ' changed');
});

child.on('restart', function() {
logger.warn('Forever restarting script for ' + child.times + ' time');
});

child.on('exit:code', function(code) {
logger.error('Forever detected script exited with code ' + code);
});

60 changes: 60 additions & 0 deletions cloud/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var publisher = require('./rabbit_lib/publisher');
var express = require("express");
var middle = require("./middlewares");
var location = require("./places/init");
var sound = require("./sounds/init");
var motion = require("./motions/init");
var logger = require("./utils/logger");


//location.init();
//motion.init();
//sound.init();

var app = express();
app.get("/debug/",function(req,res){
middle.toDebug();
res.send({"status":"debug mode","logger":"tracer"});

});

app.get("/production/",function(req,res){
middle.toProd();
res.send({"status":"production mode","logger":"logentries"});

});

app.get("/train-set/",function(req,res){
middle.isTraining();
res.send({"status":"data set is training set"});

});

app.get("/real-data/",function(req,res){
middle.isNotTraining();
res.send({"status":"data set is not training set"});


app.get("/services/motion/start/",function(req,res){

motion.init();
res.send({"status":"motion service started"});
});

app.get("/services/location/start/",function(req,res){

location.init();
res.send({"status":"location service started"})
});

app.get("/services/sound/start/",function(req,res){

sound.init();
res.send({"status":"sound service started"});
});

});
logger.info("service interchange api opened,")
app.listen(8080);


69 changes: 69 additions & 0 deletions cloud/middlewares.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Created by zhanghengyang on 15/5/4.
*/

var location = require("./places/init");
var sound = require("./sounds/init");
var motion = require("./motions/init");
var motion_log = require("./motions/lib/logger");
var location_log = require("./places/lib/logger");
var sound_log = require("./sounds/lib/logger");
var json = require("jsonfile");

var location_config = "./places/config.json";
var motion_config = "./motions/config.json";
var sound_config = "./sounds/config.json";

exports.toDebug = function(){

var l_obj = json.readFileSync(location_config);
if (l_obj.debug) {
location_log.info("location is already in debug mode");
}
else{
l_obj.debug = true;
json.writeFile(location_config,l_obj);
location_log.info("now! location is in debug mode...");

}

var m_obj = json.readFileSync(motion_config);
if (m_obj.debug) {
motion_log.info("motion is already in debug mode");
}
else{
m_obj.debug = true;
json.writeFile(motion_config,m_obj);
motion_log.info("now! motion is already in debug mode");

}

var s_obj = json.readFileSync(sound_config);
if (s_obj.debug) {
sound_log.info("location is already in debug mode");
}
else{
s_obj.debug = true;
json.writeFile(sound_config,s_obj);
motion_log.info("now! sound is already in debug mode");

}

};

//todo complete the following three functions
exports.toProd = function(){

};

exports.isNotTraining = function(){

};

exports.isTraining = function(){

};

exports.start_location_service = location.init();
exports.start_sound_service = sound.init();
exports.start_motion_service = motion.init();
Empty file added cloud/motions/README
Empty file.
26 changes: 26 additions & 0 deletions cloud/motions/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"debug":
true,
"source_db":
{
"APP_KEY": "lgxxqmbx7kcxo1sehnjme12lq91oawsmguwzikqej012tn7o" ,
"APP_ID": "2g80kca6c6opty4n9xeby7txo2uei30vlbl92csmip82xi8e",
"MASTER_KEY":"iw4zn15qtxlmhbidghl1zix6uqxi8zkgdfxln9gjpzo2emsp",
"target_class":"UserSensor"
},

"target_db":
{
"APP_KEY": "qs4o5iiywp86eznvok4tmhul360jczk7y67qj0ywbcq35iia" ,
"APP_ID": "pin72fr1iaxb7sus6newp250a4pl2n5i36032ubrck4bej81",
"MASTER_KEY":"fxnfxlh16vdd3oc740y83tvaw4pohkk5w39y01axhsu2rhqt",
"target_class":"UserMotion"
},
"serv_url" : "http://182.92.4.173/motions/",
"stat_dict":["sitting", "driving", "riding", "walking", "running"],

"log_tag": "motions ==> ",
"is_sample" : true

}

Loading

0 comments on commit 2569015

Please sign in to comment.