-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_web1.js
More file actions
74 lines (60 loc) · 1.93 KB
/
Copy path_web1.js
File metadata and controls
74 lines (60 loc) · 1.93 KB
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
// show SPAWN logs
(function() {
var childProcess = require("child_process");
var oldSpawn = childProcess.spawn;
function mySpawn() {
console.log('spawn called');
console.log(arguments);
var result = oldSpawn.apply(this, arguments);
return result;
}
childProcess.spawn = mySpawn;
})();
// Create the path of the express server to pass in with the spawn call
var webServerDirectory = path.join(__dirname, 'http', 'bin', 'www');
log.info('starting node script: ' + webServerDirectory);
var nodePath = "/usr/local/bin/node";
if (process.platform === 'win32') {
// Overwrite with the windows path...only testing on mac currently
}
// Optionally update environment variables used
var env = JSON.parse(JSON.stringify(process.env));
// Start the node express server
const spawn = require('child_process').spawn;
webServer = spawn(nodePath, [webServerDirectory], {
env: env
});
// Were we successful?
if (!webServer) {
log.info("couldn't start web server");
return;
}
// Handle standard out data from the child process
webServer.stdout.on('data', function (data) {
log.info('data: ' + data);
});
// Triggered when a child process uses process.send() to send messages.
webServer.on('message', function (message) {
log.info(message);
});
// Handle closing of the child process
webServer.on('close', function (code) {
log.info('child process exited with code ' + code);
webServer = null;
// Only restart if killed for a reason...
if (!shuttingDown) {
log.info('restarting...');
startExpress();
}
});
// Handle the stream for the child process stderr
webServer.stderr.on('data', function (data) {
log.info('stderr: ' + data);
});
// Occurs when:
// The process could not be spawned, or
// The process could not be killed, or
// Sending a message to the child process failed.
webServer.on('error', function (err) {
log.info('web server error: ' + err);
});