-
Notifications
You must be signed in to change notification settings - Fork 59
/
ircanywhere.js
156 lines (134 loc) · 4.2 KB
/
ircanywhere.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
var pkjson = require('./package.json'),
async = require('async'),
clc = require('cli-color'),
program = require('commander'),
forever = require('forever-monitor'),
util = require('util'),
fs = require('fs'),
error = function(text) { util.log(clc.red(text)); process.exit(1) },
warn = function(text) { util.log(clc.yellow(text)) };
success = function(text) { util.log(clc.green(text)) },
notice = function(text) { util.log(clc.cyanBright(text)) };
function main(argv)
{
program
.version(pkjson.version)
.option('-c, --config [filename]', 'The filename of the configuration file to use', 'config.json')
.option('-s, --stop', 'Whether to kill any running processes', false)
.parse(argv);
// setup the program with commander to handle any parameters and such
if (program.stop !== undefined && program.stop)
{
fs.readFile('irc-factory/irc-factory.pid', 'utf8', function (err, data)
{
if (err == null && data != '')
process.kill(data);
});
fs.readFile('irc-backend/irc-backend.pid', 'utf8', function (err, data)
{
if (err == null && data != '')
process.kill(data);
});
fs.readFile('frontend/frontend.pid', 'utf8', function (err, data)
{
if (err == null && data != '')
process.kill(data);
});
}
// just stop any existing processes
else
{
console.log(' ');
console.log(' _______ ________ __ ');
console.log(' / _/ _ \/ ___/ _ | ___ __ ___ __/ / ___ _______ ');
console.log(' _/ // , _/ /__/ __ |/ _ \/ // / |/|/ / _ \/ -_) __/ -_)');
console.log(' /___/_/|_|\___/_/ |_/_//_/\_, /|__,__/_//_/\__/_/ \__/ ');
console.log(' /___/ ');
console.log(' ');
console.log(' Version:', pkjson.version, ' (c) 2013 ircanywhere.com');
console.log(' ');
// display some fancy stuff, logo etc.
startFactory();
// first on the line is irc-factory, if successful, the rest will be started in sequence
}
}
function startFactory()
{
notice('[notice] attempting to fork and start irc-factory with forever');
var client = new (forever.Monitor)('lib/factory.js', {
max: 3,
silent: true,
sourceDir: 'irc-factory',
logFile: 'logs/factory.forever.log',
outFile: 'logs/factory.forever.log',
errFile: 'logs/factory.error.log',
options: [program.config]
});
client.on('start', function()
{
setTimeout(function()
{
success('[success] irc-factory successfully started');
startBackend();
}, 3000);
});
client.on('exit', function ()
{
error('[error] irc-factory has failed to start, please check logs/factory.error.log or logs/factory.forever.log');
});
client.start();
}
function startBackend()
{
notice('[notice] attempting to fork and start irc-backend with forever');
var client = new (forever.Monitor)('lib/server.js', {
max: 3,
silent: true,
sourceDir: 'irc-backend',
logFile: 'logs/backend.forever.log',
outFile: 'logs/backend.forever.log',
errFile: 'logs/backend.error.log',
options: [program.config]
});
client.on('start', function()
{
setTimeout(function()
{
success('[success] irc-backend successfully started');
startFrontend();
}, 3000);
});
client.on('exit', function ()
{
error('[error] irc-backend has failed to start, please check logs/backend.error.log or logs/backend.forever.log');
});
client.start();
}
function startFrontend()
{
notice('[notice] attempting to fork and start frontend flask server with forever');
var client = new (forever.Monitor)(['python', 'runserver.py'], {
max: 3,
silent: true,
sourceDir: 'frontend',
pidFile: 'frontend.pid',
logFile: 'logs/frontend.output.log',
outFile: 'logs/frontend.output.log',
errFile: 'logs/frontend.output.log'
});
client.on('start', function()
{
setTimeout(function()
{
success('[success] frontend successfully started');
notice('[exiting] fully started up, now exiting');
process.exit(0);
}, 3000);
});
client.on('exit', function ()
{
error('[error] frontend has failed to start, please check logs/frontend.output.log');
});
client.start();
}
main(process.argv);