diff --git a/modules/service-host.js b/modules/service-host.js index a409839..fabc4e8 100644 --- a/modules/service-host.js +++ b/modules/service-host.js @@ -187,14 +187,9 @@ function serviceHost(serviceName) console.log(e); process.exit(); } - if (process.platform == 'win32' || process.platform == 'darwin') - { - // Only do this on Windows/MacOS, becuase Linux is async... It'll complete later - console.log(this._ServiceOptions.name + ' installed'); - process.exit(); - } - i = process.argv.length; - serviceOperation = 1; + + console.log(this._ServiceOptions.name + ' installed'); + process.exit(); break; case '-uninstall': if (!this._svcManager) { this._svcManager = new serviceManager(); } diff --git a/modules/service-manager.js b/modules/service-manager.js index 7c3092b..a466789 100644 --- a/modules/service-manager.js +++ b/modules/service-manager.js @@ -292,13 +292,14 @@ function serviceManager() require('fs').chmodSync('/etc/init.d/' + options.name, m); this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); this._update._moduleName = options.name; - this._update.on('exit', function onUpdateRC_d() { console.log(this._moduleName + ' installed'); process.exit(); }); this._update.stdout.on('data', function (chunk) { }); this._update.stdin.write('update-rc.d ' + options.name + ' defaults\n'); this._update.stdin.write('exit\n'); //update-rc.d meshagent defaults # creates symlinks for rc.d //service meshagent start + this._update.waitExit(); + break; case 'systemd': var serviceDescription = options.description ? options.description : 'MeshCentral Agent'; @@ -310,11 +311,10 @@ function serviceManager() require('fs').writeFileSync('/lib/systemd/system/' + options.name + '.service', '[Unit]\nDescription=' + serviceDescription + '\n[Service]\nExecStart=/usr/local/mesh/' + options.name + '\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=' + options.name + '.service\n', { flags: 'w' }); this._update = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM }); this._update._moduleName = options.name; - this._update.on('exit', function onUpdateRC_d() { console.log(this._moduleName + ' installed'); process.exit(); }); this._update.stdout.on('data', function (chunk) { }); this._update.stdin.write('systemctl enable ' + options.name + '.service\n'); this._update.stdin.write('exit\n'); - + this._update.waitExit(); break; default: // unknown platform service type break;