diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index ff958f3..58c6960 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -710,13 +710,15 @@ int MeshAgent_Helper_IsService() char pidStr[255]; int pidStrLen = sprintf_s(pidStr, sizeof(pidStr), "%d", (int)getpid()); int retVal = 0; + int i = 0; switch (MeshAgent_Posix_GetPlatformType()) { - case MeshAgent_Posix_PlatformTypes_SYSTEMD: // Linux Systemd + case MeshAgent_Posix_PlatformTypes_SYSTEMD: // Linux Systemd if (MeshAgent_Helper_CommandLine((char*[]) { "systemctl status meshagent | grep 'Main PID:' | awk '{print $3}'\n", "exit\n", NULL }, &result, &resultLen) == 0) { - while (resultLen > 0 && (result[resultLen-1] == 10 || result[resultLen-1] == 13)) { resultLen--; } + while (i 0 && (result[resultLen-1] == 10 || result[resultLen-1] == 13)) { resultLen--; } + while (ilogUpdate != 0) { ILIBLOGMESSSAGE("SelfUpdate -> Complete... Issuing SYSTEMD restart"); } - sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "systemctl restart meshagent"); // Restart the service - ignore_result(MeshAgent_System(ILibScratchPad)); + if (agentHost->logUpdate != 0) { ILIBLOGMESSSAGE("SelfUpdate -> Complete... [SYSTEMD should auto-restart]"); } + exit(1); break; case MeshAgent_Posix_PlatformTypes_INITD: if (agentHost->logUpdate != 0) { ILIBLOGMESSSAGE("SelfUpdate -> Complete... Calling Service restart (INITD)"); } diff --git a/modules/service-manager.js b/modules/service-manager.js index 1de0d32..8c2176d 100644 --- a/modules/service-manager.js +++ b/modules/service-manager.js @@ -385,17 +385,18 @@ function serviceManager() conf.write('[Install]\n'); conf.write('WantedBy=multi-user.target\n'); conf.write('Alias=' + options.name + '.service\n'); break; + this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); + this._update._moduleName = options.name; + this._update.stdout.on('data', function (chunk) { }); + this._update.stdin.write('systemctl enable ' + options.name + '.service\n'); + this._update.stdin.write('exit\n'); + this._update.waitExit(); + default: break; } conf.end(); - this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); - this._update._moduleName = options.name; - this._update.stdout.on('data', function (chunk) { }); - this._update.stdin.write('systemctl enable ' + options.name + '.service\n'); - this._update.stdin.write('exit\n'); - this._update.waitExit(); break; default: // unknown platform service type break;