When attempting to install meshcentral as a service, I get the following response:
Installing MeshCentral as background Service...
Writing config file...
Enabling service...
ERROR: Unable to enable MeshCentral as a service: Error: Command failed: sudo systemctl enable meshcentral.service
Failed to enable unit: File meshcentral.service: Invalid argument
I'm running node ./node_modules/meshcentral/meshcentral --install while logged in as root. I attempted to add sudo, just to be sure it's not permissions related, no dice.
Node version: 12.14.1
MeshCentral version: v0.4.7-j
Thanks for the report. I just added "node meshcentral --install/--uninstall" in the last week and it's not well tested on different Linux distributions. I am traveling this week, but I will look into this.
As an alternative, you can follow the MeshCentral Install Guide available for download here. If you can post back what you needed to do on your distro, That will help me fix the --install / --uninstall commands.
Thanks,
Ylian
Hey, thanks for the response, wasn't aware this was a new feature on Linux. I dug into the code a bit and I believe I have it working.
A few issues I found:
echo -e was adding -e to the unit file (this was the main problem causing the error)whereis was including multiple paths to the node executable and node-related executables, I changed this to which node to get a more precise location.I'm going to fork this repo and do some further testing on other linux distros, but see the updated install block for linux below. Once I feel good about it, I'll submit a pull request if you want.
// Install MeshCentral in Systemd
console.log('Installing MeshCentral as background Service...');
var userinfo = require('os').userInfo(), systemdConf = null;
if (require('fs').existsSync('/etc/systemd/system')) { systemdConf = '/etc/systemd/system/meshcentral.service'; }
else if (require('fs').existsSync('/lib/systemd/system')) { systemdConf = '/lib/systemd/system/meshcentral.service'; }
else if (require('fs').existsSync('/usr/lib/systemd/system')) { systemdConf = '/usr/lib/systemd/system/meshcentral.service'; }
else { console.log('Unable to find systemd configuration folder.'); process.exit(); return; }
console.log('Writing config file...');
require('child_process').exec('which node', {}, function (error, stdout, stderr) {
if ((error != null) || (stdout.indexOf('\n') == -1)) { console.log('ERROR: Unable to get node location: ' + error); process.exit(); return; }
var nodePath = stdout.substring(0, stdout.indexOf('\n'));
var config = '[Unit]\nDescription=MeshCentral Server\n\n[Service]\nType=simple\nLimitNOFILE=1000000\nExecStart=' + nodePath + ' ' + __dirname + '/meshcentral\nWorkingDirectory=' + userinfo.homedir + '\nEnvironment=NODE_ENV=production\nUser=' + userinfo.username + '\nGroup=' + userinfo.username + '\nRestart=always\n# Restart service after 10 seconds if node service crashes\nRestartSec=10\n# Set port permissions capability\nAmbientCapabilities=cap_net_bind_service\n\n[Install]\nWantedBy=multi-user.target\n';
require('child_process').exec('echo \"' + config.split('\n').join('\\n') + '\" | sudo tee ' + systemdConf, {}, function (error, stdout, stderr) {
if ((error != null) && (error != '')) { console.log('ERROR: Unable to write config file: ' + error); process.exit(); return; }
console.log('Enabling service...');
require('child_process').exec('sudo systemctl enable meshcentral.service', {}, function (error, stdout, stderr) {
if ((error != null) && (error != '')) { console.log('ERROR: Unable to enable MeshCentral as a service: ' + error); process.exit(); return; }
if (stdout.length > 0) { console.log(stdout); }
console.log('Starting service...');
require('child_process').exec('sudo systemctl start meshcentral.service', {}, function (error, stdout, stderr) {
if ((error != null) && (error != '')) { console.log('ERROR: Unable to start MeshCentral as a service: ' + error); process.exit(); return; }
if (stdout.length > 0) { console.log(stdout); }
console.log('Done.');
});
});
});
});
return;
Submitted a pull request with a fix for this. Ran into a small issue on CentOS with how the line breaks are transformed when writing the unit file. Should be good to go.
Published MeshCentral v0.4.7-k with the fix for this.
Most helpful comment
Submitted a pull request with a fix for this. Ran into a small issue on CentOS with how the line breaks are transformed when writing the unit file. Should be good to go.
827