-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathservice.js
69 lines (55 loc) · 1.48 KB
/
service.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
"use strict";
var app = 'index',
name = 'mootools-website';
var Monitor = require('forever-monitor').Monitor,
log = require('./lib/log.js');
var monitor = new Monitor(__dirname + '/' + app + '.js', {
silent: true,
minUptime: 2000,
args: process.argv.splice(2)
});
log.attach(monitor);
try {
log.configure(require('./config/log.json'));
} catch (error){
}
function stop(){
log.error('** Requested stop of ' + name);
monitor.stop();
}
function reload(){
log.error('** Requested reload of ' + name);
log.reload();
monitor.restart();
}
function reloadLogs(){
log.error('** Requested log reload of ' + name);
log.reload();
}
process.addListener('SIGINT', stop);
process.addListener('SIGTERM', stop);
process.addListener('SIGHUP', reload);
process.addListener('SIGUSR2', reloadLogs);
monitor.addListener('start', function(){
log.error('** Starting ' + name + ' monitor');
});
monitor.addListener('stop', function(){
log.error('** Stopping ' + name + ' monitor');
});
monitor.addListener('exit:code', function(code){
if (code == null) code = 0;
log.error('** Detected ' + name + ' process exited (exit code ' + code + ')');
});
monitor.addListener('restart', function(){
log.error('** Restarting ' + name + ' process (#' + monitor.times + ')');
});
monitor.addListener('error', function(error){
if (error.stack){
log.error('** ' + error.stack);
} else if (error.message) {
log.error('** Error: ' + error.message);
} else {
log.error('** Error: ' + error);
}
});
monitor.start();