1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-15 15:53:55 +00:00

Updated service-manager for systemd, to use full name of service when calling stop/start/restart/status

This commit is contained in:
Bryan Roe
2021-09-07 16:44:58 -07:00
parent 1eae8ef45e
commit c5e347335e
2 changed files with 11 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1885,7 +1885,7 @@ 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("systemctl status " + this.name + " | grep 'Main PID:' | awk 'NR==1{print $3}'\nexit\n"); child.stdin.write("systemctl status " + this.name + ".service | grep 'Main PID:' | awk 'NR==1{print $3}'\nexit\n");
child.waitExit(); child.waitExit();
return (parseInt(child.stdout.str.trim()) == process.pid); return (parseInt(child.stdout.str.trim()) == process.pid);
}; };
@@ -1894,33 +1894,33 @@ 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("systemctl status " + this.name + " | grep 'Active:' | awk 'NR==1{print $2}'\nexit\n"); child.stdin.write("systemctl status " + this.name + ".service | grep 'Active:' | awk 'NR==1{print $2}'\nexit\n");
child.waitExit(); child.waitExit();
return (child.stdout.str.trim() == 'active'); return (child.stdout.str.trim() == 'active');
}; };
ret.start = function start() { ret.start = function start() {
var child = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); var child = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
child.stdout.on('data', function (chunk) { }); child.stdout.on('data', function (chunk) { });
child.stdin.write('systemctl start ' + this.name + '\nexit\n'); child.stdin.write('systemctl start ' + this.name + '.service\nexit\n');
child.waitExit(); child.waitExit();
}; };
ret.stop = function stop() { ret.stop = function stop() {
var child = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); var child = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
child.stdout.on('data', function (chunk) { }); child.stdout.on('data', function (chunk) { });
child.stdin.write('systemctl stop ' + this.name + '\nexit\n'); child.stdin.write('systemctl stop ' + this.name + '.service\nexit\n');
child.waitExit(); child.waitExit();
}; };
ret.restart = function restart() { ret.restart = function restart() {
var child = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); var child = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
child.stdout.on('data', function (chunk) { }); child.stdout.on('data', function (chunk) { });
child.stdin.write('systemctl restart ' + this.name + '\nexit\n'); child.stdin.write('systemctl restart ' + this.name + '.service\nexit\n');
child.waitExit(); child.waitExit();
}; };
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('systemctl status ' + this.name + '\nexit\n'); child.stdin.write('systemctl status ' + this.name + '.service\nexit\n');
child.waitExit(); child.waitExit();
return (child.stdout._str); return (child.stdout._str);
}; };