add support for running a service
This commit is contained in:
parent
3cbfd0c478
commit
308b46c26a
1 changed files with 19 additions and 3 deletions
|
@ -1,9 +1,11 @@
|
||||||
|
using System.Diagnostics;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using netsd.Utils;
|
||||||
using StartGrpc;
|
using StartGrpc;
|
||||||
|
|
||||||
namespace netsd.Handlers;
|
namespace netsd.Handlers;
|
||||||
|
@ -36,11 +38,25 @@ public class Init
|
||||||
|
|
||||||
public class StartGrpc : StartRpc.StartRpcBase
|
public class StartGrpc : StartRpc.StartRpcBase
|
||||||
{
|
{
|
||||||
public override Task<StartReply> StartService(StartRequest request, ServerCallContext context)
|
public override async Task<StartReply> StartService(StartRequest request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
return Task.FromResult(new StartReply
|
var parseServiceFile = await ServiceParser.Parse(request.Path);
|
||||||
|
|
||||||
|
using var startService = new Process();
|
||||||
|
startService.StartInfo.CreateNoWindow = true;
|
||||||
|
startService.StartInfo.FileName = parseServiceFile.ExecStart?.Split(' ').First();
|
||||||
|
startService.StartInfo.Arguments = string.Join(" ", parseServiceFile.ExecStart?.Split(' ').Skip(1)!);
|
||||||
|
|
||||||
|
startService.Start();
|
||||||
|
|
||||||
|
startService.OutputDataReceived += (sender, args) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(args);
|
||||||
|
};
|
||||||
|
|
||||||
|
return new StartReply
|
||||||
{
|
{
|
||||||
Success = true,
|
Success = true,
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue