-
Notifications
You must be signed in to change notification settings - Fork 1
/
app
90 lines (74 loc) · 1.83 KB
/
app
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
#!/usr/bin/env node
'use strict';
var fs = require('fs'),
cliArgs = process.argv,
action = cliArgs[2] || 'start',
forever = require('forever'),
actionMap = {
'start': start,
'stop' : stop,
'list' : list
};
var PATH_TO_SERVER = './src';
var UID = 'BackendlessProManager';
var PROCESS_LIST;
forever.list(false, function(context, list) {
PROCESS_LIST = list;
try {
var method = actionMap[action];
if (method) {
method.call();
} else {
forever.out.error('Unknown command [' + action + ']. Please use one of the following: "start", "stop", "list"');
}
} catch (e) {
forever.out.error('Exception throw in attempt to [' + action + '] with message: ' + e);
}
});
function start() {
var logsDir = __dirname + '/logs/';
var options = {
uid : UID,
max : 5,
silent : false,
watch : false,
killTree: true,
logFile : logsDir + UID + '.log',
env: {
DEBUG: 'SAT*'
}
},
proc = getProcess(PROCESS_LIST);
if (proc && proc.running) {
forever.out.info(UID + ' is already started');
process.exit(0);
} else if (proc) {
stop();
}
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir);
}
forever.startDaemon(PATH_TO_SERVER, options);
forever.out.info('Started');
}
function stop() {
var proc = getProcess(PROCESS_LIST);
if (!proc) {
forever.out.info('Nothing to stop');
process.exit(0);
}
if (proc && proc.running) {
forever.stop(UID, true);
} else {
forever.kill(proc.foreverPid, true);
}
forever.out.info('Stopped');
}
function list() {
forever.list(true, function(context, list) {
console.log(list);
});
}
function getProcess(processList) {
return processList && processList.find(proc => proc.uid === UID);
}