@nginstack/engine-node 60.0.1 → 60.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/Engine.js +38 -29
- package/package.json +2 -2
package/README.md
CHANGED
package/lib/Engine.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const child_process = require('child_process');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const url = require('url');
|
|
5
4
|
const del = require('del');
|
|
6
5
|
const request = require('request');
|
|
7
6
|
const getPort = require('get-port');
|
|
@@ -15,7 +14,7 @@ const net = require('net');
|
|
|
15
14
|
|
|
16
15
|
tmp.setGracefulCleanup();
|
|
17
16
|
|
|
18
|
-
const ENGINE_APP = '
|
|
17
|
+
const ENGINE_APP = os.platform() == 'win32' ? 'engine64.exe' : 'engine';
|
|
19
18
|
const NGINT_APP_PATH = '/bin/win64/ngint.exe';
|
|
20
19
|
const EXIT_CODE_RESTART_REQUIRED = 4;
|
|
21
20
|
const ENGINE_STATUS_URL = '/api/service-status/v1/status';
|
|
@@ -79,6 +78,7 @@ class Engine {
|
|
|
79
78
|
this.v8_ = options.v8 || false;
|
|
80
79
|
this.startupTimeout = options.startupTimeout || ENGINE_STARTUP_TIMEOUT;
|
|
81
80
|
this.startedSuccessfully = false;
|
|
81
|
+
this.inShutdown_ = false;
|
|
82
82
|
this.redirectLogsToStdout_ = options.redirectLogsToStdout || false;
|
|
83
83
|
this.onEngineClose_ = null;
|
|
84
84
|
if (options.instanceId) {
|
|
@@ -125,15 +125,10 @@ class Engine {
|
|
|
125
125
|
this.monitorTimeoutId_ = null;
|
|
126
126
|
}
|
|
127
127
|
this.monitorEnabled_ = true;
|
|
128
|
-
request.get(
|
|
129
|
-
protocol: 'http',
|
|
130
|
-
hostname: 'localhost',
|
|
131
|
-
port: this.httpPort,
|
|
132
|
-
pathname: ENGINE_STATUS_URL
|
|
133
|
-
}), (error, response) => {
|
|
128
|
+
request.get(`http://localhost:${this.httpPort}${ENGINE_STATUS_URL}`, (_error, response) => {
|
|
134
129
|
if (response && response.statusCode) {
|
|
135
130
|
this.lastStatusCode_ = response.statusCode;
|
|
136
|
-
if (this.lastStatusCode_ === 500) {
|
|
131
|
+
if (this.lastStatusCode_ === 500 && !this.inShutdown_) {
|
|
137
132
|
console.info(`Engine response (${response.statusCode}):\n${response.body}`);
|
|
138
133
|
}
|
|
139
134
|
} else {
|
|
@@ -250,9 +245,12 @@ class Engine {
|
|
|
250
245
|
if (!httpUrl.startsWith('http://') && !httpUrl.startsWith('https://')) {
|
|
251
246
|
httpUrl = 'http://' + httpUrl;
|
|
252
247
|
}
|
|
253
|
-
request.get(
|
|
248
|
+
request.get(new URL(ENGINE_DOWNLOAD_URL, httpUrl).toString())
|
|
254
249
|
.pipe(fs.createWriteStream(this.enginePath))
|
|
255
250
|
.on('close', () => {
|
|
251
|
+
if (os.platform() != 'win32') {
|
|
252
|
+
fs.chmodSync(path.join(this.installPath, ENGINE_APP), '755');
|
|
253
|
+
}
|
|
256
254
|
resolve();
|
|
257
255
|
})
|
|
258
256
|
.on('error', (reqErr) => {
|
|
@@ -329,10 +327,13 @@ class Engine {
|
|
|
329
327
|
args.push('--additionalLoggerConfig=\'' + logConfig + '\'');
|
|
330
328
|
}
|
|
331
329
|
|
|
332
|
-
this.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
330
|
+
this.inShutdown_ = false;
|
|
331
|
+
this.process_ = child_process.spawn(path.join(this.installPath, ENGINE_APP),
|
|
332
|
+
args,
|
|
333
|
+
{
|
|
334
|
+
cwd: this.installPath,
|
|
335
|
+
windowsHide: true
|
|
336
|
+
});
|
|
336
337
|
|
|
337
338
|
this.process_.on('error', (err) => {
|
|
338
339
|
console.error('Error starting Engine process:', err);
|
|
@@ -423,6 +424,7 @@ class Engine {
|
|
|
423
424
|
} else {
|
|
424
425
|
resolve();
|
|
425
426
|
}
|
|
427
|
+
this.inShutdown_ = false;
|
|
426
428
|
};
|
|
427
429
|
this.sendShutdownCommand_();
|
|
428
430
|
} else {
|
|
@@ -438,21 +440,28 @@ class Engine {
|
|
|
438
440
|
sendShutdownCommand_() {
|
|
439
441
|
if (this.process_) {
|
|
440
442
|
let forceKill = true;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
443
|
+
this.inShutdown_ = true;
|
|
444
|
+
if (os.platform() == 'win32') {
|
|
445
|
+
if (fs.existsSync(this.ngintPath_)) {
|
|
446
|
+
try {
|
|
447
|
+
console.info('Shutdown command sent to Engine process');
|
|
448
|
+
child_process.execFileSync(
|
|
449
|
+
this.ngintPath_,
|
|
450
|
+
['shutdown', this.process_.pid, ENGINE_SHUTDOWN_TIMEOUT],
|
|
451
|
+
{
|
|
452
|
+
cwd: this.installPath,
|
|
453
|
+
windowsHide: true
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
forceKill = false;
|
|
457
|
+
} catch (e) {
|
|
458
|
+
console.error('Error stopping Engine', e);
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
console.info('ngint was not found');
|
|
455
462
|
}
|
|
463
|
+
} else {
|
|
464
|
+
process.kill(this.process_.pid, 'SIGTERM');
|
|
456
465
|
}
|
|
457
466
|
if (forceKill) {
|
|
458
467
|
console.info('Kill signal sent to Engine process');
|
|
@@ -506,7 +515,7 @@ class Engine {
|
|
|
506
515
|
const hash = crypto.createHash('sha256');
|
|
507
516
|
hash.update(os.hostname());
|
|
508
517
|
hash.update(getWorkspacePath());
|
|
509
|
-
return ('_' + hash.digest('hex').toUpperCase()).
|
|
518
|
+
return ('_' + hash.digest('hex').toUpperCase()).substring(0, INSTANCE_ID_LENGTH);
|
|
510
519
|
}
|
|
511
520
|
}
|
|
512
521
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nginstack/engine-node",
|
|
3
|
-
"version": "60.0.
|
|
3
|
+
"version": "60.0.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"thread-sleep": "^2.2.0",
|
|
25
25
|
"tmp": "^0.2.1"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "827772c130491ba242eabe4dff2d42d6d309bc37"
|
|
28
28
|
}
|