-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·96 lines (83 loc) · 3.47 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Created by zhanghengyang on 15/5/4.
*/
var log= require("./service_router/utils/logger").log;
var logger = new log("forever server");
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 logs.
//
'watch': true, // Value indicating if we should watch logs.
'watchIgnoreDotFiles': true, // Whether to ignore file starting with a '.'
'watchIgnorePatterns': null, // Ignore patterns to use when watching logs.
'watchDirectory': "./service_router/", // 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 logs and associated logging options for this instance
//
'logFile': './logs/logfile', // Path to log output from forever process (when daemonized)
'outFile': './logs/output', // Path to log output from child stdout
'errFile': './logs/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)("./service_router/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);
});
child.start();