diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 691b878..3e2aa0d 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -3687,22 +3687,6 @@ void MeshServer_Agent_SelfTest(MeshAgentHostContainer *agent) free(CoreModule); } - //printf(" -> Loading Test Script from db ..."); - //if (CoreModuleTesterLen == 0) - //{ - // printf("[NOT FOUND]\n"); - // return; - //} - - //ILibMemory_AllocateRaw(CoreModuleTester, CoreModuleTesterLen); - //ILibSimpleDataStore_Get(agent->masterDb, "CoreModuleTester", CoreModuleTester, CoreModuleTesterLen); - //if (ILibDuktape_ModSearch_AddModule(agent->meshCoreCtx, "meshcore-test", CoreModuleTester, (int)CoreModuleTesterLen) != 0) - //{ - // printf("[ERROR]\n"); - // return; - //} - //printf("[OK]\n"); - if (duk_peval_string(agent->meshCoreCtx, "require('agent-selftest')();") != 0) { printf(" -> Loading Test Script.................[FAILED]\n"); diff --git a/modules/agent-selftest.js b/modules/agent-selftest.js index 764e30d..bf5bf9e 100644 --- a/modules/agent-selftest.js +++ b/modules/agent-selftest.js @@ -44,8 +44,23 @@ var promise = require('promise'); function start() { - console.log('\nStarting Self Test...'); + var isservice = false; + var service = null; + try + { + service = require('service-manager').manager.getService(process.platform == 'win32' ? 'Mesh Agent' : 'meshagent'); + isservice = service.isMe(); + } + catch(e) + { + } + if (isservice) + { + console.setDestination(console.Destinations.LOGFILE); + } + + console.log('Starting Self Test...'); coreInfo() .then(function () { return (testLMS()); }) .then(function () { return (testConsoleHelp()); }) @@ -54,8 +69,30 @@ function start() .then(function () { return (testTerminal()); }) .then(function () { return (testKVM()); }) .then(function () { return (testFileDownload()); }) - .then(function () { console.log('End of Self Test'); }) - .catch(function (v) { console.log(v); }); + .then(function () + { + console.log('End of Self Test'); + if (isservice) + { + service.stop(); + } + else + { + process._exit(); + } + }) + .catch(function (v) + { + console.log(v); + if (isservice) + { + service.stop(); + } + else + { + process._exit(); + } + }); } function getFDSnapshot()