forked from ptcrealitylab/vuforia-spatial-edge-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 906 Bytes
/
index.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
'use strict';
const fork = require('child_process').fork;
const path = require('path');
const program = path.resolve('server.js');
const parameters = [];
const options = {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
};
let child = null;
function startNewChild() {
child = fork(program, parameters, options);
child.on('message', onChildMessage);
child.on('exit', onChildCrash);
}
function onChildMessage(message) {
if (message === 'restart') {
console.log('message from child:', message);
child.removeListener('exit', onChildCrash);
child.kill();
startNewChild();
} else if (message === 'exit') {
child.removeListener('exit', onChildCrash);
child.kill();
}
}
function onChildCrash() {
console.info('server.js has exited unexpectedly, restarting');
child = fork(program, parameters, options);
}
startNewChild();