1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 15:53:55 +00:00

Updated, so on upstart platforms, it uses initctl instead of service, to fix problems on older upstart platforms that don't map service to initctl.

This commit is contained in:
Bryan Roe
2019-03-14 02:53:44 -07:00
parent 3c694116e6
commit 6352c35e22
3 changed files with 91 additions and 14 deletions

View File

@@ -582,6 +582,7 @@ typedef enum MeshAgent_Posix_PlatformTypes
MeshAgent_Posix_PlatformTypes_UNKNOWN = 0,
MeshAgent_Posix_PlatformTypes_SYSTEMD = 1,
MeshAgent_Posix_PlatformTypes_INITD = 2,
MeshAgent_Posix_PlatformTypes_INIT_UPSTART =4,
MeshAgent_Posix_PlatformTypes_LAUNCHD = 3,
}MeshAgent_Posix_PlatformTypes;
@@ -634,9 +635,18 @@ MeshAgent_Posix_PlatformTypes MeshAgent_Posix_GetPlatformType()
retVal = MeshAgent_Posix_PlatformTypes_SYSTEMD;
}
else if (tlen == 4 && strncasecmp(tstr, "init", 4) == 0)
{
struct stat result;
memset(&result, 0, sizeof(struct stat));
if (stat("/etc/init", &result) != 0)
{
retVal = MeshAgent_Posix_PlatformTypes_INITD;
}
else
{
retVal = MeshAgent_Posix_PlatformTypes_INIT_UPSTART;
}
}
fini = 1;
}
}
@@ -744,6 +754,17 @@ int MeshAgent_Helper_IsService()
}
}
break;
case MeshAgent_Posix_PlatformTypes_INIT_UPSTART:
if (MeshAgent_Helper_CommandLine((char*[]) { "initctl status meshagent | awk '{print $4}'\n", "exit\n", NULL }, &result, &resultLen) == 0)
{
while (i<resultLen && result[i] != 10) { ++i; }
resultLen = i;
if (resultLen == pidStrLen && strncmp(result, pidStr, resultLen) == 0)
{
retVal = 1;
}
}
break;
case MeshAgent_Posix_PlatformTypes_LAUNCHD: // MacOS Launchd
if (MeshAgent_Helper_CommandLine((char*[]) { "launchctl list\n", "exit\n", NULL }, &result, &resultLen) == 0)
{
@@ -4398,6 +4419,11 @@ int MeshAgent_Start(MeshAgentHostContainer *agentHost, int paramLen, char **para
sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "service meshagent restart"); // Restart the service
ignore_result(MeshAgent_System(ILibScratchPad));
break;
case MeshAgent_Posix_PlatformTypes_INIT_UPSTART:
if (agentHost->logUpdate != 0) { ILIBLOGMESSSAGE("SelfUpdate -> Complete... Calling initctl restart (UPSTART)"); }
sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "initctl restart meshagent"); // Restart the service
ignore_result(MeshAgent_System(ILibScratchPad));
break;
default:
break;
}

File diff suppressed because one or more lines are too long

View File

@@ -272,6 +272,8 @@ function serviceManager()
{
case 'init':
case 'upstart':
if (require('fs').existsSync('/etc/init.d/' + name)) { platform = 'init'; }
if (require('fs').existsSync('/etc/init/' + name + '.conf')) { platform = 'upstart'; }
if ((platform == 'init' && require('fs').existsSync('/etc/init.d/' + name)) ||
(platform == 'upstart' && require('fs').existsSync('/etc/init/' + name + '.conf')))
{
@@ -297,49 +299,97 @@ function serviceManager()
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
if (isMe.platform == 'upstart')
{
child.stdin.write("initctl status " + this.name + " | awk '{print $2}' | awk -F, '{print $4}'\nexit\n");
}
else
{
child.stdin.write("service " + this.name + " status | awk '{print $2}' | awk -F, '{print $4}'\nexit\n");
}
child.waitExit();
return (parseInt(child.stdout.str.trim()) == process.pid);
};
ret.isMe.platform = platform;
ret.isRunning = function isRunning()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
if (isRunning.platform == 'upstart')
{
child.stdin.write("initctl status " + this.name + " | awk '{print $2}' | awk -F, '{print $1}'\nexit\n");
}
else
{
child.stdin.write("service " + this.name + " status | awk '{print $2}' | awk -F, '{print $1}'\nexit\n");
}
child.waitExit();
return (child.stdout.str.trim() == 'start/running');
};
ret.isRunning.platform = platform;
ret.start = function start()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.on('data', function (chunk) { });
if (start.platform == 'upstart')
{
child.stdin.write('initctl start ' + this.name + '\nexit\n');
}
else
{
child.stdin.write('service ' + this.name + ' start\nexit\n');
}
child.waitExit();
};
ret.start.platform = platform;
ret.stop = function stop()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.on('data', function (chunk) { });
if (stop.platform == 'upstart')
{
child.stdin.write('initctl stop ' + this.name + '\nexit\n');
}
else
{
child.stdin.write('service ' + this.name + ' stop\nexit\n');
}
child.waitExit();
};
ret.stop.platform = platform;
ret.restart = function restart()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.on('data', function (chunk) { });
if (restart.platform == 'upstart')
{
child.stdin.write('initctl restart ' + this.name + '\nexit\n');
}
else
{
child.stdin.write('service ' + this.name + ' restart\nexit\n');
}
child.waitExit();
};
ret.restart.platform = platform;
ret.status = function status()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout._str = '';
child.stdout.on('data', function (chunk) { this._str += chunk.toString(); });
if (status.platform == 'upstart')
{
child.stdin.write('initctl status ' + this.name + '\nexit\n');
}
else
{
child.stdin.write('service ' + this.name + ' status\nexit\n');
}
child.waitExit();
return (child.stdout._str);
};
ret.status.platform = platform;
return (ret);
}
else