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:
File diff suppressed because one or more lines are too long
@@ -33,7 +33,7 @@ function windows_notifybar_system(title, tsid)
|
||||
{
|
||||
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)
|
||||
.createEvent('close')
|
||||
|
||||
@@ -921,7 +921,7 @@ function serviceManager()
|
||||
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
|
||||
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
|
||||
{
|
||||
|
||||
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
const SYNCHRONIZE = 0x00100000;
|
||||
|
||||
|
||||
function invalid()
|
||||
{
|
||||
@@ -152,6 +154,25 @@ function getLibc()
|
||||
|
||||
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)
|
||||
{
|
||||
case 'linux':
|
||||
@@ -161,4 +182,9 @@ switch (process.platform)
|
||||
default:
|
||||
module.exports = { getOpenDescriptors: invalid, closeDescriptors: invalid };
|
||||
break;
|
||||
}
|
||||
|
||||
if (process.platform == 'win32')
|
||||
{
|
||||
module.exports.getProcessHandle = win_getProcessHandle;
|
||||
}
|
||||
Reference in New Issue
Block a user