1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-02 00:23:17 +00:00

Fixed service.restart() for self, for FreeBSD

This commit is contained in:
Bryan Roe
2021-01-29 22:09:50 -08:00
parent 464f756f6e
commit d540fd64c8
2 changed files with 21 additions and 4 deletions

View File

@@ -1173,11 +1173,28 @@ function serviceManager()
};
ret.restart = function restart()
{
if (this.isMe())
{
var parameters = this.parameters();
require('child_process')._execve(process.execPath, parameters);
throw ('Error Restarting via execve()');
}
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write("service " + this.name + " onerestart\nexit\n");
child.waitExit();
};
ret.parameters = function parameters()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write("cat " + this.rc + ' | grep "^\\s*command_args=" | awk \'NR==1');
child.stdin.write('{ gsub(/^\\s*command_args=/,"",$0); gsub(/^"([^\\\\^\\/]+)/,"\\"",$0); print $0; }\'\nexit\n');
child.waitExit();
var str = JSON.parse(child.stdout.str.trim());
return (str.match(/(?:[^\s"]+|"[^"]*")+/g));
};
return (ret);
};
}