mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
Updated service-manager for MacOS:
1. Added start, stop, restart 2. Added isRunning, isMe
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -301,15 +301,13 @@ function serviceManager()
|
||||
}
|
||||
if (process.platform == 'darwin')
|
||||
{
|
||||
// cat meshagent_osx64_LaunchDaemon.plist | tr '\n' '\.' | awk '{ split($0, a, "<key>WorkingDirectory</key>"); split(a[2], b, "</string>"); split(b[1], c, "<string>"); print c[2]; }'
|
||||
this.getService = function (name)
|
||||
{
|
||||
var ret = { name: name };
|
||||
if(!require('fs').existsSync('/Library/LaunchDaemons/' + name + '.plist'))
|
||||
{
|
||||
throw (' LaunchDaemon (' + name + ') NOT FOUND');
|
||||
}
|
||||
|
||||
var ret = { name: name };
|
||||
ret.label = function label()
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
@@ -319,16 +317,25 @@ function serviceManager()
|
||||
child.waitExit();
|
||||
return (child.stdout.str.trim());
|
||||
}
|
||||
Object.defineProperty(ret, 'alias', { value: ret.label() });
|
||||
ret.label = null;
|
||||
ret.getPID = function getPID()
|
||||
{
|
||||
var serviceName = this.label();
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = '';
|
||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdin.write("launchctl list | grep '" + serviceName + "' | awk '{ if($3==\"" + serviceName + "\"){print $1;}}'\nexit\n");
|
||||
child.stdin.write("launchctl list | grep '" + this.alias + "' | awk '{ if($3==\"" + this.alias + "\"){print $1;}}'\nexit\n");
|
||||
child.waitExit();
|
||||
return (parseInt(child.stdout.str.trim()));
|
||||
};
|
||||
ret.isRunning = function isRunning()
|
||||
{
|
||||
return (this.getPID() > 0);
|
||||
};
|
||||
ret.isMe = function isMe()
|
||||
{
|
||||
return (this.getPID() == process.pid);
|
||||
};
|
||||
ret.appWorkingDirectory = function appWorkingDirectory()
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
@@ -349,6 +356,25 @@ function serviceManager()
|
||||
child.waitExit();
|
||||
return (child.stdout.str.trim());
|
||||
};
|
||||
ret.start = function start()
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.on('data', function (chunk) { });
|
||||
child.stdin.write('launchctl start ' + this.alias + '\nexit\n');
|
||||
child.waitExit();
|
||||
};
|
||||
ret.stop = function stop()
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.on('data', function (chunk) { });
|
||||
child.stdin.write('launchctl stop ' + this.alias + '\nexit\n');
|
||||
child.waitExit();
|
||||
};
|
||||
ret.restart = function restart()
|
||||
{
|
||||
this.stop();
|
||||
this.start();
|
||||
};
|
||||
return (ret);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user