1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-11 13:53:37 +00:00

Updated service restart on Windows, when called from self.

This commit is contained in:
Bryan Roe
2021-02-07 15:26:53 -08:00
parent 66e489c49c
commit 43c5f2d1b5
4 changed files with 34 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@@ -33,7 +33,7 @@ function windows_notifybar_system(title, tsid)
{ {
var ret = {}; var ret = {};
var script = Buffer.from("require('notifybar-desktop')('" + title + "').on('close', function(){process._exit();});").toString('base64'); var script = Buffer.from("require('notifybar-desktop')('" + title + "').on('close', function(){process._exit();});require('DescriptorEvents').addDescriptor(require('util-descriptors').getProcessHandle(" + process.pid + ")).on('signaled', function(){process._exit();});").toString('base64');
require('events').EventEmitter.call(ret, true) require('events').EventEmitter.call(ret, true)
.createEvent('close') .createEvent('close')

View File

@@ -921,7 +921,7 @@ function serviceManager()
if (this.isMe()) if (this.isMe())
{ {
// In order to restart ourselves on Windows, we must spawn a detached child process, becuase we need to call start, once we are stopped // In order to restart ourselves on Windows, we must spawn a detached child process, becuase we need to call start, once we are stopped
child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-exec "' + "require('service-manager').manager.getService('" + this.name + "').restart().finally(function(){process.exit();});" + '"'], { type: 4, detached: true }); require('child_process')._execve(process.env['windir'] + '\\system32\\cmd.exe', ['cmd.exe', '/C wmic service "' + this.name + '" call stopservice & wmic service "' + this.name + '" call startservice']);
} }
else else
{ {

View File

@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const SYNCHRONIZE = 0x00100000;
function invalid() function invalid()
{ {
@@ -152,6 +154,25 @@ function getLibc()
return (libc); return (libc);
} }
function win_getProcessHandle(pid)
{
try
{
if(!this.kernel32)
{
this.kernel32 = require('_GenericMarshal').CreateNativeProxy('kernel32.dll');
this.kernel32.CreateMethod('OpenProcess');
}
return (this.kernel32.OpenProcess(SYNCHRONIZE, 0, pid));
}
catch(e)
{
return (null);
}
}
switch (process.platform) switch (process.platform)
{ {
case 'linux': case 'linux':
@@ -161,4 +182,9 @@ switch (process.platform)
default: default:
module.exports = { getOpenDescriptors: invalid, closeDescriptors: invalid }; module.exports = { getOpenDescriptors: invalid, closeDescriptors: invalid };
break; break;
}
if (process.platform == 'win32')
{
module.exports.getProcessHandle = win_getProcessHandle;
} }