Archived
0
0
Fork 0

add support for running a service

This commit is contained in:
Daryl Ronningen 2022-11-17 18:31:19 -08:00
parent 3cbfd0c478
commit 308b46c26a
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B

View file

@ -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<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,
});
};
}
}