Fixed Windows Service Stop

Ylian Saint-Hilaire committed Jul 17, 2019 at 17:34 UTC c641b2d5858b1aa10c367c590a37fec9c71ebacf
2 files changed +16 -16
meshcentral.js
+15 -15
@@ -169,24 +169,22 @@ function CreateMeshCentralServer(config, args) {
169 obj.StartEx();
170 } else {
171 // if "--launch" is not specified, launch the server as a child process.
172 - var startLine = '';
172 + var startArgs = [];
173 for (i in process.argv) {
174 - var arg = process.argv[i];
175 - if (arg.length > 0) {
176 - if (startLine.length > 0) startLine += ' ';
177 - if ((arg.indexOf(' ') >= 0) || (arg.indexOf('&') >= 0)) { startLine += '"' + arg + '"'; } else { startLine += arg; }
174 + if (i > 0) {
175 + var arg = process.argv[i];
176 + if ((arg.length > 0) && ((arg.indexOf(' ') >= 0) || (arg.indexOf('&') >= 0))) { startArgs.push('"' + arg + '"'); } else { startArgs.push(arg); }
177 }
178 }
180 - obj.launchChildServer(startLine);
179 + startArgs.push('--launch', process.pid);
180 + obj.launchChildServer(startArgs);
181 }
182 };
183
184 // Launch MeshCentral as a child server and monitor it.
185 - obj.launchChildServer = function (startLine) {
186 - if (process.pid) { obj.updateServerState('monitor-pid', process.pid); }
187 - if (process.ppid) { obj.updateServerState('monitor-ppid', process.ppid); }
185 + obj.launchChildServer = function (startArgs) {
186 var child_process = require('child_process');
189 - childProcess = child_process.exec(startLine + ' --launch ' + process.pid, { maxBuffer: Infinity, cwd: obj.parentpath }, function (error, stdout, stderr) {
187 + childProcess = child_process.execFile(process.argv[0], startArgs, { maxBuffer: Infinity, cwd: obj.parentpath }, function (error, stdout, stderr) {
188 if (childProcess.xrestart == 1) {
189 setTimeout(function () { obj.launchChildServer(startLine); }, 500); // This is an expected restart.
190 } else if (childProcess.xrestart == 2) {
@@ -568,7 +566,7 @@ function CreateMeshCentralServer(config, args) {
566 // Write the server state
567 obj.updateServerState('state', 'starting');
568 if (process.pid) { obj.updateServerState('server-pid', process.pid); }
571 - if (process.ppid) { obj.updateServerState('server-ppid', process.ppid); }
569 + if (process.ppid) { obj.updateServerState('server-parent-pid', process.ppid); }
570
571 // Start memory tracking if requested
572 if (typeof obj.args.memorytracking == 'number') {
@@ -1849,10 +1847,12 @@ function mainStart() {
1847 process.on("exit", function () { if (childProcess) { childProcess.kill(); childProcess = null; } });
1848
1849 // If our parent exits, we also exit
1852 - process.stderr.on('end', function () { process.exit(); });
1853 - process.stdout.on('end', function () { process.exit(); });
1854 - process.stdin.on('end', function () { process.exit(); });
1855 - process.stdin.on('data', function (data) { });
1850 + if (args.launch) {
1851 + process.stderr.on('end', function () { process.exit(); });
1852 + process.stdout.on('end', function () { process.exit(); });
1853 + process.stdin.on('end', function () { process.exit(); });
1854 + process.stdin.on('data', function (data) { });
1855 + }
1856 });
1857 }
1858
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.3.7-y",
3 + "version": "0.3.7-z",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",