Added RunOnServerStarted, RunOnServerUpdated, RunOnServerError options. #3768
Ylian Saint-Hilaire committed
Mar 17, 2022 at 11:19 UTC
e3205137e5cd253e77e8d82a7c38487d7b5adb61
4 files changed
+33
-1
file1.txt
new
+1
@@ -0,0 +1 @@
1
+0.9.99
meshcentral-config-schema.json
+3
@@ -129,6 +129,9 @@
129
},
130
"required": [ "email" ]
131
},
132
+ "RunOnServerStarted": { "type": "boolean", "default": null, "description": "Execute this when the server startup is completed. The first parameter will be the server version." },
133
+ "RunOnServerUpdated": { "type": "boolean", "default": null, "description": "Execute this when the server has been updated. The first parameter will be the server version." },
134
+ "RunOnServerError": { "type": "boolean", "default": null, "description": "Execute this when the server has to restart due to an error. The first parameter will be the server version." },
135
"publicPushNotifications": { "type": "boolean", "default": false, "description": "When true, this server uses MeshCentral.com a push notification relay for Android notifications. Push notifications work even if the Android app is not open." },
136
"desktopMultiplex": { "type": "boolean", "default": false, "description": "When true, enabled a server modules that efficiently splits a remote desktop stream to multiple browsers. Also allows slow browsers to not slow down the session for fast ones, this comes at the cost of extra server memory and processing for all remote desktop sessions." },
137
"ipBlockedUserRedirect" : { "type": "string", "default": null, "description": "If set, a user from a banned IP address will be redirected to this URL." },
meshcentral.js
+26
-1
@@ -471,6 +471,15 @@ function CreateMeshCentralServer(config, args) {
471
xxprocess.stderr.on('data', function (data) { xxprocess.data += data; });
472
xxprocess.on('close', function (code) {
473
if (code == 0) { console.log('Update completed...'); }
474
+
475
+ // Run the server updated script if present
476
+ if (typeof obj.config.settings.runonserverupdated == 'string') {
477
+ const child_process = require('child_process');
478
+ var parentpath = __dirname;
479
+ if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); }
480
+ child_process.exec(obj.config.settings.runonserverupdated + ' ' + getCurrentVersion(), { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) { });
481
+ }
482
+
483
if (obj.args.cleannpmcacheonupdate === true) {
484
// Perform NPM cache clean
485
console.log('Cleaning NPM cache...');
@@ -487,6 +496,14 @@ function CreateMeshCentralServer(config, args) {
496
console.log(error);
497
console.log('ERROR: MeshCentral failed with critical error, check mesherrors.txt. Restarting in 5 seconds...');
498
setTimeout(function () { obj.launchChildServer(startArgs); }, 5000);
499
+
500
+ // Run the server error script if present
501
+ if (typeof obj.config.settings.runonservererror == 'string') {
502
+ const child_process = require('child_process');
503
+ var parentpath = __dirname;
504
+ if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); }
505
+ child_process.exec(obj.config.settings.runonservererror + ' ' + getCurrentVersion(), { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) { });
506
+ }
507
}
508
}
509
});
@@ -1856,6 +1873,14 @@ function CreateMeshCentralServer(config, args) {
1873
var ipKvmSupport = false;
1874
for (var i in obj.config.domains) { if (obj.config.domains[i].ipkvm == true) { ipKvmSupport = true; } }
1875
if (ipKvmSupport) { obj.ipKvmManager = require('./meshipkvm').CreateIPKVMManager(obj); }
1876
+
1877
+ // Run the server start script if present
1878
+ if (typeof obj.config.settings.runonserverstarted == 'string') {
1879
+ const child_process = require('child_process');
1880
+ var parentpath = __dirname;
1881
+ if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); }
1882
+ child_process.exec(obj.config.settings.runonserverstarted + ' ' + getCurrentVersion(), { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) { });
1883
+ }
1884
}
1885
1886
// Refresh any certificate hashs from the reverse proxy
@@ -3334,7 +3359,7 @@ function InstallModules(modules, func) {
3359
// Check if a module is present and install it if missing
3360
function InstallModule(modulename, func, tag1, tag2) {
3361
console.log('Installing ' + modulename + '...');
3337
- var child_process = require('child_process');
3362
+ const child_process = require('child_process');
3363
var parentpath = __dirname;
3364
3365
// Get the working directory
sample-config-advanced.json
+3
@@ -75,6 +75,9 @@
75
"_mpsAliasHost": "mps.mydomain.com",
76
"_mpsTlsOffload": true,
77
"_no2FactorAuth": true,
78
+ "_runOnServerStarted": "c:\\tmp\\mcstart.bat",
79
+ "_runOnServerUpdated": "c:\\tmp\\mcupdate.bat",
80
+ "_runOnServerError": "c:\\tmp\\mcerror.bat",
81
"_log": "main,web,webrequest,cert",
82
"_syslog": "meshcentral",
83
"_syslogauth": "meshcentral-auth",