Added option to auto-clean NPM cache on update. #3225

Ylian Saint-Hilaire committed Oct 28, 2021 at 23:00 UTC 0b38049015001512b689f9f742c2d09064fcb87e
3 files changed +10 -1
agents/MeshCentralRouterCmd.exe
Binary files /dev/null and b/agents/MeshCentralRouterCmd.exe differ
meshcentral-config-schema.json
+1
@@ -97,6 +97,7 @@
97 "webRTC": { "type": "boolean", "default": false, "description": "When enabled, allows use of WebRTC to allow direct network traffic between the agent and browser." },
98 "nice404": { "type": "boolean", "default": true, "description": "By default, a nice looking 404 error page is displayed when needed. Set this to false to disable it." },
99 "selfUpdate": { "type": "boolean", "default": false, "description": "When true, this server will attempt to self-update everyday after midnight." },
100 + "cleanNpmCacheOnUpdate": { "type": "boolean", "default": false, "description": "When true, run \"npm cache clean --force\" to reclame disk space." },
101 "browserPing": { "type": "integer", "minimum": 1, "description": "When specified, sends data to the browser at x seconds interval and expects a response from the browser." },
102 "browserPong": { "type": "integer", "minimum": 1, "description": "When specified, sends data to the browser at x seconds interval." },
103 "agentsInRam": { "type": "boolean", "default": false, "description": "Loads all agent binaries in RAM for faster agent updates." },
meshcentral.js
+9 -1
@@ -467,7 +467,15 @@ function CreateMeshCentralServer(config, args) {
467 xxprocess.stderr.on('data', function (data) { xxprocess.data += data; });
468 xxprocess.on('close', function (code) {
469 if (code == 0) { console.log('Update completed...'); }
470 - setTimeout(function () { obj.launchChildServer(startArgs); }, 1000);
470 + if (obj.args.cleannpmcacheonupdate === true) {
471 + // Perform NPM cache clean
472 + console.log('Cleaning NPM cache...');
473 + var xxxprocess = child_process.exec(npmpath + ' cache clean --force', { maxBuffer: Infinity, cwd: obj.parentpath, env: env }, function (error, stdout, stderr) { });
474 + xxxprocess.on('close', function (code) { setTimeout(function () { obj.launchChildServer(startArgs); }, 1000); });
475 + } else {
476 + // Run the updated server
477 + setTimeout(function () { obj.launchChildServer(startArgs); }, 1000);
478 + }
479 });
480 } else {
481 if (error != null) {