mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-21 10:43:36 +00:00
1. Added Wayland helper
2. Fixed agent customization support for Docker/PseudoService
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -120,6 +120,126 @@ if (process.platform == 'linux')
|
|||||||
return (uu);
|
return (uu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function waylandStatus()
|
||||||
|
{
|
||||||
|
var wayland = true;
|
||||||
|
|
||||||
|
if (require('fs').existsSync('/etc/gdm/custom.conf'))
|
||||||
|
{
|
||||||
|
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 /etc/gdm/custom.conf | grep WaylandEnable= | tr '\\n' '`' | awk -F'`' '");
|
||||||
|
child.stdin.write('{');
|
||||||
|
child.stdin.write(' wayland=1;');
|
||||||
|
child.stdin.write(' for(n=1;n<NF;++n) ');
|
||||||
|
child.stdin.write(' {');
|
||||||
|
child.stdin.write(' if($n~/^#/) { continue; }')
|
||||||
|
child.stdin.write(' gsub(/ /, "", $n);');
|
||||||
|
child.stdin.write(' if($n~/^WaylandEnable=/)');
|
||||||
|
child.stdin.write(' {');
|
||||||
|
child.stdin.write(' split($n, dummy, "WaylandEnable=");');
|
||||||
|
child.stdin.write(' if(dummy[2]=="false")');
|
||||||
|
child.stdin.write(' {');
|
||||||
|
child.stdin.write(' wayland=0;');
|
||||||
|
child.stdin.write(' }');
|
||||||
|
child.stdin.write(' break;');
|
||||||
|
child.stdin.write(' }');
|
||||||
|
child.stdin.write(' }');
|
||||||
|
child.stdin.write(' print wayland;');
|
||||||
|
child.stdin.write("}'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
if (child.stdout.str.trim() == '0')
|
||||||
|
{
|
||||||
|
wayland = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (require('fs').existsSync('/etc/gdm3/custom.conf'))
|
||||||
|
{
|
||||||
|
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 /etc/gdm3/custom.conf | grep WaylandEnable= | tr '\\n' '`' | awk -F'`' '");
|
||||||
|
child.stdin.write('{');
|
||||||
|
child.stdin.write(' wayland=1;');
|
||||||
|
child.stdin.write(' for(n=1;n<NF;++n) ');
|
||||||
|
child.stdin.write(' {');
|
||||||
|
child.stdin.write(' if($n~/^#/) { continue; }')
|
||||||
|
child.stdin.write(' gsub(/ /, "", $n);');
|
||||||
|
child.stdin.write(' if($n~/^WaylandEnable=/)');
|
||||||
|
child.stdin.write(' {');
|
||||||
|
child.stdin.write(' split($n, dummy, "WaylandEnable=");');
|
||||||
|
child.stdin.write(' if(dummy[2]=="false")');
|
||||||
|
child.stdin.write(' {');
|
||||||
|
child.stdin.write(' wayland=0;');
|
||||||
|
child.stdin.write(' }');
|
||||||
|
child.stdin.write(' break;');
|
||||||
|
child.stdin.write(' }');
|
||||||
|
child.stdin.write(' }');
|
||||||
|
child.stdin.write(' print wayland;');
|
||||||
|
child.stdin.write("}'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
if (child.stdout.str.trim() == '0')
|
||||||
|
{
|
||||||
|
wayland = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (wayland);
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableWayland()
|
||||||
|
{
|
||||||
|
if (waylandStatus())
|
||||||
|
{
|
||||||
|
if (require('fs').existsSync('/etc/gdm/custom.conf'))
|
||||||
|
{
|
||||||
|
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('sed "s/#WaylandEnable=false/WaylandEnable=false/g" /etc/gdm/custom.conf > /etc/gdm/custom_2.conf\n');
|
||||||
|
child.stdin.write("mv /etc/gdm/custom_2.conf /etc/gdm/custom.conf\n");
|
||||||
|
child.stdin.write("\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
|
if (require('fs').existsSync('/etc/gdm3/custom.conf'))
|
||||||
|
{
|
||||||
|
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('sed "s/#WaylandEnable=false/WaylandEnable=false/g" /etc/gdm3/custom.conf > /etc/gdm3/custom_2.conf\n');
|
||||||
|
child.stdin.write("mv /etc/gdm3/custom_2.conf /etc/gdm3/custom.conf\n");
|
||||||
|
child.stdin.write("\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function enableWayland()
|
||||||
|
{
|
||||||
|
if (!waylandStatus())
|
||||||
|
{
|
||||||
|
if (require('fs').existsSync('/etc/gdm/custom.conf'))
|
||||||
|
{
|
||||||
|
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('sed "s/WaylandEnable=false/#WaylandEnable=false/g" /etc/gdm/custom.conf > /etc/gdm/custom_2.conf\n');
|
||||||
|
child.stdin.write("mv /etc/gdm/custom_2.conf /etc/gdm/custom.conf\n");
|
||||||
|
child.stdin.write("\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
|
if (require('fs').existsSync('/etc/gdm3/custom.conf'))
|
||||||
|
{
|
||||||
|
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('sed "s/WaylandEnable=false/#WaylandEnable=false/g" /etc/gdm3/custom.conf > /etc/gdm3/custom_2.conf\n');
|
||||||
|
child.stdin.write("mv /etc/gdm3/custom_2.conf /etc/gdm3/custom.conf\n");
|
||||||
|
child.stdin.write("\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function waylandDM()
|
||||||
|
{
|
||||||
|
if (require('fs').existsSync('/etc/gdm/custom.conf')) { return ('gdm'); }
|
||||||
|
if (require('fs').existsSync('/etc/gdm3/custom.conf')) { return ('gdm3'); }
|
||||||
|
return ('');
|
||||||
|
}
|
||||||
module.exports =
|
module.exports =
|
||||||
{
|
{
|
||||||
createVirtualSession: spawnVirtualSession,
|
createVirtualSession: spawnVirtualSession,
|
||||||
@@ -127,6 +247,10 @@ if (process.platform == 'linux')
|
|||||||
users: getUsers,
|
users: getUsers,
|
||||||
loginUids: loginUids,
|
loginUids: loginUids,
|
||||||
allowed: allowedUIDs,
|
allowed: allowedUIDs,
|
||||||
|
waylandStatus: waylandStatus,
|
||||||
|
disableWayland: disableWayland,
|
||||||
|
enableWayland: enableWayland,
|
||||||
|
waylandDM: waylandDM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1954,7 +1954,7 @@ function serviceManager()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Peudo Service (meshDaemon)
|
// Pseudo Service (meshDaemon)
|
||||||
if (require('fs').existsSync('/usr/local/mesh_daemons/' + name + '.service'))
|
if (require('fs').existsSync('/usr/local/mesh_daemons/' + name + '.service'))
|
||||||
{
|
{
|
||||||
ret.conf = '/usr/local/mesh_daemons/' + name + '.service';
|
ret.conf = '/usr/local/mesh_daemons/' + name + '.service';
|
||||||
@@ -1988,14 +1988,15 @@ function serviceManager()
|
|||||||
var parameters = this.parameters();
|
var parameters = this.parameters();
|
||||||
var location = wd + parameters.shift();
|
var location = wd + parameters.shift();
|
||||||
|
|
||||||
var options = { pidPath: wd + 'pid', logOutputs: false, crashRestart: respawn, cwd: wd };
|
var options = { pidPath: wd + 'pid', logOutputs: true, crashRestart: respawn, cwd: wd };
|
||||||
require('service-manager').manager.daemon(location, parameters, options);
|
require('service-manager').manager.daemon(location, parameters, options);
|
||||||
};
|
};
|
||||||
ret.stop = function stop()
|
ret.stop = function stop()
|
||||||
{
|
{
|
||||||
|
var pidpath = this.appWorkingDirectory().split(' ').join('\\ ') + 'pid';
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stdin.write('cat /usr/local/mesh_daemons/' + name + '/pid \nexit\n');
|
child.stdin.write('cat ' + pidpath + '\nexit\n');
|
||||||
child.waitExit();
|
child.waitExit();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -2020,9 +2021,10 @@ function serviceManager()
|
|||||||
}
|
}
|
||||||
ret.isMe = function isMe()
|
ret.isMe = function isMe()
|
||||||
{
|
{
|
||||||
|
var pidpath = this.appWorkingDirectory().split(' ').join('\\ ') + 'pid';
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stdin.write('cat /usr/local/mesh_daemons/' + name + '/pid \nexit\n');
|
child.stdin.write('cat ' + pidpath + '\nexit\n');
|
||||||
child.waitExit();
|
child.waitExit();
|
||||||
var pid = child.stdout.str.trim();
|
var pid = child.stdout.str.trim();
|
||||||
if (pid == '') { return (false); }
|
if (pid == '') { return (false); }
|
||||||
@@ -2050,11 +2052,14 @@ function serviceManager()
|
|||||||
};
|
};
|
||||||
ret.isRunning = function isRunning()
|
ret.isRunning = function isRunning()
|
||||||
{
|
{
|
||||||
if(require('fs').existsSync('/usr/local/mesh_daemons/' + name + '/pid'))
|
var pidpath = this.appWorkingDirectory() + 'pid';
|
||||||
|
console.log('pidpath', pidpath);
|
||||||
|
|
||||||
|
if(require('fs').existsSync(pidpath))
|
||||||
{
|
{
|
||||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
child.stdin.write('cat /usr/local/mesh_daemons/' + name + '/pid \nexit\n');
|
child.stdin.write('cat ' + pidpath.split(' ').join('\\ ') + '\nexit\n');
|
||||||
child.waitExit();
|
child.waitExit();
|
||||||
var pid = child.stdout.str.trim();
|
var pid = child.stdout.str.trim();
|
||||||
|
|
||||||
@@ -2806,10 +2811,10 @@ function serviceManager()
|
|||||||
require('fs').chmodSync('/usr/local/mesh_daemons/' + options.name + '/' + options.target, m);
|
require('fs').chmodSync('/usr/local/mesh_daemons/' + options.name + '/' + options.target, m);
|
||||||
|
|
||||||
conf = require('fs').createWriteStream('/usr/local/mesh_daemons/' + options.name + '.service', { flags: 'wb' });
|
conf = require('fs').createWriteStream('/usr/local/mesh_daemons/' + options.name + '.service', { flags: 'wb' });
|
||||||
conf.write('workingDirectory=' + '/usr/local/mesh_daemons/' + options.name + '\n');
|
conf.write('workingDirectory=' + '/usr/local/mesh_daemons/' + (options.companyName!=null?(options.companyName + '/'):'') + options.name + '\n');
|
||||||
|
|
||||||
if(!options.parameters) {options.parameters = [];}
|
if(!options.parameters) {options.parameters = [];}
|
||||||
options.parameters.unshift(options.name);
|
options.parameters.unshift(options.target);
|
||||||
conf.write('parameters=' + JSON.stringify(options.parameters) + '\n');
|
conf.write('parameters=' + JSON.stringify(options.parameters) + '\n');
|
||||||
options.parameters.shift();
|
options.parameters.shift();
|
||||||
if (options.failureRestart == null || options.failureRestart > 0)
|
if (options.failureRestart == null || options.failureRestart > 0)
|
||||||
@@ -3330,6 +3335,7 @@ function serviceManager()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._platform = platform;
|
this._platform = platform;
|
||||||
return (platform);
|
return (platform);
|
||||||
};
|
};
|
||||||
@@ -3370,14 +3376,40 @@ function serviceManager()
|
|||||||
|
|
||||||
this.daemon = function daemon(path, parameters, options)
|
this.daemon = function daemon(path, parameters, options)
|
||||||
{
|
{
|
||||||
|
require('code-utils');
|
||||||
|
console.log('PATH => ' + JSON.stringify(path, null, 1));
|
||||||
|
console.log('parameters => ' + JSON.stringify(parameters, null, 1));
|
||||||
|
console.log('options => ' + JSON.stringify(options, null, 1));
|
||||||
|
|
||||||
|
var z = parameters.getParameterIndex('meshServiceName');
|
||||||
|
console.log('meshServiceName => ' + z);
|
||||||
|
if (z >= 0)
|
||||||
|
{
|
||||||
|
parameters.splice(z, 1);
|
||||||
|
console.log('parameters => ' + JSON.stringify(parameters, null, 1));
|
||||||
|
}
|
||||||
|
|
||||||
var tmp = JSON.stringify(parameters);
|
var tmp = JSON.stringify(parameters);
|
||||||
tmp = tmp.substring(1, tmp.length - 1);
|
tmp = tmp.substring(1, tmp.length - 1);
|
||||||
|
|
||||||
|
if (options.cwd)
|
||||||
|
{
|
||||||
|
process.chdir(options.cwd);
|
||||||
|
console.log('Setting CWD to: ' + options.cwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console.log('\n\n');
|
||||||
|
console.log("child = require('child_process').execFile('" + path + "', ['" + (process.platform == 'win32' ? path.split('\\').pop() : path.split('/').pop() + "'" + (tmp != '' ? (", " + tmp) : "")) + "]);");
|
||||||
|
console.log('\n\n');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!options) { options = {}; }
|
if (!options) { options = {}; }
|
||||||
var childParms = "\
|
var childParms = "\
|
||||||
var child = null; \
|
var child = null; \
|
||||||
var options = " + JSON.stringify(options) + ";\
|
var options = " + JSON.stringify(options) + ";\
|
||||||
if(options.logOutput)\
|
if(options.logOutputs)\
|
||||||
{ console.setDestination(console.Destinations.LOGFILE); console.log('Logging Outputs...'); }\
|
{ console.setDestination(console.Destinations.LOGFILE); console.log('Logging Outputs...'); }\
|
||||||
else\
|
else\
|
||||||
{\
|
{\
|
||||||
@@ -3397,8 +3429,14 @@ function serviceManager()
|
|||||||
child.stderr.on('data', function(c) { console.log(c.toString()); });\
|
child.stderr.on('data', function(c) { console.log(c.toString()); });\
|
||||||
child.once('exit', function (code) \
|
child.once('exit', function (code) \
|
||||||
{\
|
{\
|
||||||
|
console.log('Child Exited');\
|
||||||
if(options.crashRestart) { spawnChild(); } else { cleanupAndExit(); }\
|
if(options.crashRestart) { spawnChild(); } else { cleanupAndExit(); }\
|
||||||
});\
|
});\
|
||||||
|
console.log('Child Spawned');\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
{\
|
||||||
|
console.log('Child Spawn Failed');\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
if(options.pidPath) { require('fs').writeFileSync(options.pidPath, process.pid.toString()); }\
|
if(options.pidPath) { require('fs').writeFileSync(options.pidPath, process.pid.toString()); }\
|
||||||
|
|||||||
Reference in New Issue
Block a user