1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-18 01:03:14 +00:00

Updated PID handling for OpenBSD

This commit is contained in:
Bryan Roe
2021-08-31 13:38:54 -07:00
parent 294fc2f492
commit d4cdabef31
2 changed files with 61 additions and 21 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1196,18 +1196,35 @@ function serviceManager()
}; };
ret.pid = function pid() ret.pid = function pid()
{ {
var child = require('child_process').execFile('/bin/sh', ['sh']); if (this.OpenBSD)
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); {
child.stdin.write("service " + this.name + " onestatus | awk '"); // OpenBSD
child.stdin.write('{ split($6, res, "."); '); try
child.stdin.write(' cm=sprintf("ps -p %s -w", res[1]);'); {
child.stdin.write(' system(cm); ') var pid = require('fs').readFileSync('/var/run/' + this.name + '.pid');
child.stdin.write('}\' | awk \'NR>1\' | awk \''); return(parseInt(pid.toString().trim()));
child.stdin.write('{'); }
child.stdin.write(' if($5=="daemon:") { split($0, T, "["); split(T[2], X, "]"); print X[1]; } else { print $1; }'); catch(e)
child.stdin.write('}\'\nexit\n'); {
child.waitExit(); return (-1);
return (parseInt(child.stdout.str.trim())); }
}
else
{
// FreeBSD
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 + " onestatus | awk '");
child.stdin.write('{ split($6, res, "."); ');
child.stdin.write(' cm=sprintf("ps -p %s -w", res[1]);');
child.stdin.write(' system(cm); ')
child.stdin.write('}\' | awk \'NR>1\' | awk \'');
child.stdin.write('{');
child.stdin.write(' if($5=="daemon:") { split($0, T, "["); split(T[2], X, "]"); print X[1]; } else { print $1; }');
child.stdin.write('}\'\nexit\n');
child.waitExit();
return (parseInt(child.stdout.str.trim()));
}
}; };
ret.isMe = function isMe() ret.isMe = function isMe()
{ {
@@ -1256,10 +1273,22 @@ function serviceManager()
throw ('Error Restarting via execve()'); throw ('Error Restarting via execve()');
} }
var child = require('child_process').execFile('/bin/sh', ['sh']); if (this.OpenBSD)
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); {
child.stdin.write("service " + this.name + " onerestart\nexit\n"); // OpenBSD
child.waitExit(); 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("rcctl restart " + this.name + "\nexit\n");
child.waitExit();
}
else
{
// FreeBSD
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() ret.parameters = function parameters()
{ {
@@ -3119,6 +3148,17 @@ function serviceManager()
{ {
require('fs').unlinkSync(service.appLocation()); require('fs').unlinkSync(service.appLocation());
} }
if (this.OpenBSD)
{
// OpenBSD specific
try
{
require('fs').unlinkSync(workingPath + name + '_loader');
}
catch(e)
{
}
}
if (this.pfSense) if (this.pfSense)
{ {
try try