1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 07:43:50 +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;
@@ -635,7 +636,16 @@ MeshAgent_Posix_PlatformTypes MeshAgent_Posix_GetPlatformType()
}
else if (tlen == 4 && strncasecmp(tstr, "init", 4) == 0)
{
retVal = MeshAgent_Posix_PlatformTypes_INITD;
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;
}