-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
59 lines (47 loc) · 1.93 KB
/
start.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
var $ = require("jquery");
var fs = require('node-fs');
var config = require('./config');
var forever = require('forever-monitor');
var crontab = require('crontab');
var path = require('path');
var util = require('util');
//Update Crontab
crontab.load(function(err, tab) {
require('npm').load(function (err, npm) {
if (err) { console.log(err); process.exit(1); }
var npmPrefix = npm.config.get('prefix');
var npmBinRoot = path.join(npmPrefix, 'bin');
var nodePath = process.execPath.split('/').slice(0, -1).join('/');
var exportCommand = 'export PATH=' + nodePath + ':$PATH';
var foreverCommand = path.join(npmBinRoot, 'forever');
var thisCommand = __filename;
var sysCommand = util.format('%s && %s start %s', exportCommand, foreverCommand, thisCommand);
tab.remove(tab.findComment("laborate_proxy_server"));
tab.create(sysCommand, "laborate_proxy_server").everyReboot();
tab.remove(tab.findComment("scout_realtime"));
tab.create(util.format('%s && /usr/local/bin/scout_realtime start', exportCommand), "scout_realtime").everyReboot();
tab.save();
});
});
//Create Logs Folder
fs.mkdirSync(__dirname + '/../logs/' + config.forever.uid, 0775, true);
//Configure Forever
var child = new (forever.Monitor)(__dirname + '/server.js', {
uid: config.forever.uid,
max: config.forever.max_failures,
silent: config.forever.silent,
watch: config.forever.watch,
watchDirectory: __dirname + "/" + config.forever.watch_directory,
watchIgnoreDotFiles: config.forever.watch_ignore_dot,
watchIgnorePatterns: $.map(config.forever.watch_ignore_patterns, function(value) {
return __dirname + "/" + value;
}),
env: {
'NODE_ENV': "development"
},
outFile: __dirname + "/" + config.forever.output_log,
errFile: __dirname + "/" + config.forever.error_log,
killTree: true
});
//Start Forver
child.start();