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:
@@ -582,6 +582,7 @@ typedef enum MeshAgent_Posix_PlatformTypes
|
|||||||
MeshAgent_Posix_PlatformTypes_UNKNOWN = 0,
|
MeshAgent_Posix_PlatformTypes_UNKNOWN = 0,
|
||||||
MeshAgent_Posix_PlatformTypes_SYSTEMD = 1,
|
MeshAgent_Posix_PlatformTypes_SYSTEMD = 1,
|
||||||
MeshAgent_Posix_PlatformTypes_INITD = 2,
|
MeshAgent_Posix_PlatformTypes_INITD = 2,
|
||||||
|
MeshAgent_Posix_PlatformTypes_INIT_UPSTART =4,
|
||||||
MeshAgent_Posix_PlatformTypes_LAUNCHD = 3,
|
MeshAgent_Posix_PlatformTypes_LAUNCHD = 3,
|
||||||
}MeshAgent_Posix_PlatformTypes;
|
}MeshAgent_Posix_PlatformTypes;
|
||||||
|
|
||||||
@@ -635,7 +636,16 @@ MeshAgent_Posix_PlatformTypes MeshAgent_Posix_GetPlatformType()
|
|||||||
}
|
}
|
||||||
else if (tlen == 4 && strncasecmp(tstr, "init", 4) == 0)
|
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;
|
fini = 1;
|
||||||
}
|
}
|
||||||
@@ -744,6 +754,17 @@ int MeshAgent_Helper_IsService()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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
|
case MeshAgent_Posix_PlatformTypes_LAUNCHD: // MacOS Launchd
|
||||||
if (MeshAgent_Helper_CommandLine((char*[]) { "launchctl list\n", "exit\n", NULL }, &result, &resultLen) == 0)
|
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
|
sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "service meshagent restart"); // Restart the service
|
||||||
ignore_result(MeshAgent_System(ILibScratchPad));
|
ignore_result(MeshAgent_System(ILibScratchPad));
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -272,6 +272,8 @@ function serviceManager()
|
|||||||
{
|
{
|
||||||
case 'init':
|
case 'init':
|
||||||
case 'upstart':
|
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)) ||
|
if ((platform == 'init' && require('fs').existsSync('/etc/init.d/' + name)) ||
|
||||||
(platform == 'upstart' && require('fs').existsSync('/etc/init/' + name + '.conf')))
|
(platform == 'upstart' && require('fs').existsSync('/etc/init/' + name + '.conf')))
|
||||||
{
|
{
|
||||||
@@ -297,49 +299,97 @@ function serviceManager()
|
|||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = '';
|
child.stdout.str = '';
|
||||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||||
child.stdin.write("service " + this.name + " status | awk '{print $2}' | awk -F, '{print $4}'\nexit\n");
|
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();
|
child.waitExit();
|
||||||
return (parseInt(child.stdout.str.trim()) == process.pid);
|
return (parseInt(child.stdout.str.trim()) == process.pid);
|
||||||
};
|
};
|
||||||
|
ret.isMe.platform = platform;
|
||||||
ret.isRunning = function isRunning()
|
ret.isRunning = function isRunning()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = '';
|
child.stdout.str = '';
|
||||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||||
child.stdin.write("service " + this.name + " status | awk '{print $2}' | awk -F, '{print $1}'\nexit\n");
|
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();
|
child.waitExit();
|
||||||
return (child.stdout.str.trim() == 'start/running');
|
return (child.stdout.str.trim() == 'start/running');
|
||||||
};
|
};
|
||||||
|
ret.isRunning.platform = platform;
|
||||||
ret.start = function start()
|
ret.start = function start()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.on('data', function (chunk) { });
|
child.stdout.on('data', function (chunk) { });
|
||||||
child.stdin.write('service ' + this.name + ' start\nexit\n');
|
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();
|
child.waitExit();
|
||||||
};
|
};
|
||||||
|
ret.start.platform = platform;
|
||||||
ret.stop = function stop()
|
ret.stop = function stop()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.on('data', function (chunk) { });
|
child.stdout.on('data', function (chunk) { });
|
||||||
child.stdin.write('service ' + this.name + ' stop\nexit\n');
|
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();
|
child.waitExit();
|
||||||
};
|
};
|
||||||
|
ret.stop.platform = platform;
|
||||||
ret.restart = function restart()
|
ret.restart = function restart()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.on('data', function (chunk) { });
|
child.stdout.on('data', function (chunk) { });
|
||||||
child.stdin.write('service ' + this.name + ' restart\nexit\n');
|
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();
|
child.waitExit();
|
||||||
};
|
};
|
||||||
|
ret.restart.platform = platform;
|
||||||
ret.status = function status()
|
ret.status = function status()
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout._str = '';
|
child.stdout._str = '';
|
||||||
child.stdout.on('data', function (chunk) { this._str += chunk.toString(); });
|
child.stdout.on('data', function (chunk) { this._str += chunk.toString(); });
|
||||||
child.stdin.write('service ' + this.name + ' status\nexit\n');
|
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();
|
child.waitExit();
|
||||||
return (child.stdout._str);
|
return (child.stdout._str);
|
||||||
};
|
};
|
||||||
|
ret.status.platform = platform;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user