diff --git a/netsd/Handlers/Init.cs b/netsd/Handlers/Init.cs index 89b124f..178ae79 100644 --- a/netsd/Handlers/Init.cs +++ b/netsd/Handlers/Init.cs @@ -1,9 +1,11 @@ +using System.Diagnostics; using Grpc.Core; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using netsd.Utils; using StartGrpc; namespace netsd.Handlers; @@ -36,11 +38,25 @@ public class Init public class StartGrpc : StartRpc.StartRpcBase { - public override Task StartService(StartRequest request, ServerCallContext context) + public override async Task 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, - }); + }; } }