-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcinabox.js
executable file
·104 lines (93 loc) · 3.63 KB
/
dcinabox.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
#!/usr/bin/env node
'use strict';
const daemon = require('./index.js');
const parseArgs = require('minimist');
const XIP_SUFFIX = process.env.XIP_SUFFIX ||'xip.io';
const usage = function() {
const msg =
'Usage: dcinabox.js --envProp <string> --appLocalName <string>' +
' --ipAddress <string> --port <string> --appImage ' +
'<string> [--appWorkingDir <string>] [--hostVolume <string>] ' +
'[--appVolume <string>] [--debugApplication <boolean>]';
console.log(msg);
process.exit(1);
};
const argv = parseArgs(process.argv.slice(2), {
string: ['appImage', 'appLocalName', 'appWorkingDir', 'ipAddress', 'port',
'hostVolume', 'appVolume', 'envProp'],
boolean: ['debugApplication'],
alias: {i: 'appImage', n: 'appLocalName', h: 'appWorkingDir',
v: 'hostVolume', a: 'appVolume', d: 'debugApplication'},
unknown: usage
});
const spec = { env: {}};
const addOpt = function(x){
if (argv[x]) {
spec.env[x] = argv[x];
}
};
addOpt('envProp');
addOpt('appImage');
addOpt('appLocalName');
addOpt('appWorkingDir');
addOpt('hostVolume');
addOpt('appVolume');
addOpt('ipAddress');
addOpt('port');
addOpt('debugApplication'); // default is 'false', so noop is ok...
if (typeof spec.env.ipAddress === 'string') {
//using an externally visible address
process.env.APP_SUFFIX = spec.env.ipAddress + '.' + XIP_SUFFIX;
process.env.HOST_IP=spec.env.ipAddress;
if (spec.env.port) {
process.env.HTTP_EXTERNAL_PORT = spec.env.port;
process.env.HTTP_INTERNAL_PORT = spec.env.port;
process.env.ACCOUNTS_URL='http://root-accounts.' +
spec.env.ipAddress + '.' + XIP_SUFFIX + ':' + spec.env.port;
process.env.IOT_DEVICE_MANAGER_APP_URL = 'http://root-gadget.' +
spec.env.ipAddress + '.' + XIP_SUFFIX + ':' + spec.env.port;
} else {
process.env.HTTP_INTERNAL_PORT = null; //using default port, i.e., 80
process.env.ACCOUNTS_URL='http://root-accounts.' +
spec.env.ipAddress + '.' + XIP_SUFFIX;
process.env.IOT_DEVICE_MANAGER_APP_URL = 'http://root-gadget.' +
spec.env.ipAddress + '.' + XIP_SUFFIX;
}
console.log(' **** USE URL http://root-launcher.' +
spec.env.ipAddress + '.' + XIP_SUFFIX +
(spec.env.port ? ':' + spec.env.port : ''));
} else if (spec.env.port) {
const appSuffix = process.env.APP_SUFFIX || 'localtest.me';
process.env.HTTP_EXTERNAL_PORT = spec.env.port;
process.env.HTTP_INTERNAL_PORT = spec.env.port;
process.env.CONTAINER_PORT = spec.env.port; // container port === external
process.env.ACCOUNTS_URL='http://root-accounts.' + appSuffix +
':' + spec.env.port;
process.env.IOT_DEVICE_MANAGER_APP_URL = 'http://root-gadget.' + appSuffix +
':' + spec.env.port;
console.log(' **** USE URL http://root-launcher.' + appSuffix +
':' + spec.env.port);
}
console.log(spec.env);
if (spec.env.debugApplication) {
process.env.NODE_DEBUG_OPTIONS='--inspect=0.0.0.0:9229';
process.env.LOG_LEVEL='DEBUG';
process.env.COMPRESS_STATE=false;
}
if (spec.env.appLocalName && (spec.env.appImage)) {
daemon.run([module], null, spec, function(err, top) {
if (err) {
console.log('Error: ' + err);
} else {
console.log('Starting DC in a box...');
process.on('SIGINT', function() {
console.log('Caught interrupt signal');
top.__ca_graceful_shutdown__(null, function(err) {
console.log('shutdown:' + (err ? err : 'OK'));
});
});
}
});
} else {
usage();
}