From 63fb8da896288762861a9433e8781097925e2721 Mon Sep 17 00:00:00 2001 From: egallup02360 <41955146+egallup02360@users.noreply.github.com> Date: Mon, 13 Jan 2020 13:34:10 -0500 Subject: [PATCH 1/3] Fix install on Linux --- meshcentral.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index b3d9468e..f415331c 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -163,11 +163,11 @@ function CreateMeshCentralServer(config, args) { 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('whereis node', {}, function (error, stdout, stderr) { - if ((error != null) || (stdout.startsWith('node: ') == false) || (stdout.indexOf('\n') == -1)) { console.log('ERROR: Unable to get node location: ' + error); process.exit(); return; } - var nodePath = stdout.substring(6, stdout.indexOf('\n')); - var config = '[Unit]\nDescription=MeshCentral Server\n\n[Service]\nType=simple\nLimitNOFILE=1000000\nExecStart=' + nodePath + ' ' + __dirname + '\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 -e \"' + config.split('\n').join('\\n') + '\" | sudo tee ' + systemdConf, {}, function (error, stdout, stderr) { + 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) { From 90095e81287e8cf5c97c8ae7b494c92e7d2c2396 Mon Sep 17 00:00:00 2001 From: egallup02360 <41955146+egallup02360@users.noreply.github.com> Date: Mon, 13 Jan 2020 14:23:13 -0500 Subject: [PATCH 2/3] Fix new lines in config on CentOS --- meshcentral.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshcentral.js b/meshcentral.js index f415331c..c808915e 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -167,7 +167,7 @@ function CreateMeshCentralServer(config, args) { 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) { + 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) { From dadb66da2e3e4ac09eb4984856a02e7c62eb2b64 Mon Sep 17 00:00:00 2001 From: egallup02360 <41955146+egallup02360@users.noreply.github.com> Date: Tue, 14 Jan 2020 08:17:12 -0500 Subject: [PATCH 3/3] No need to do anything with the config string --- meshcentral.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshcentral.js b/meshcentral.js index c808915e..f4e71e5b 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -167,7 +167,7 @@ function CreateMeshCentralServer(config, args) { 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) { + require('child_process').exec('echo \"' + config + '\" | 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) {