Archived
0
0
Fork 0

add simple service file parsing

This commit is contained in:
Daryl Ronningen 2022-11-16 21:05:23 -08:00
parent 84ac974427
commit 71c50ded5c
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
4 changed files with 28 additions and 5 deletions

View file

@ -3,10 +3,12 @@ using StartGrpc;
namespace netsd.Handlers; namespace netsd.Handlers;
public class Start public static class Start
{ {
public Start() public static async Task StartAsync()
{ {
var parseServiceFile = await ServiceParser.Parse("/lib/systemd/system/sddm.service");
Console.WriteLine($"ExecStart: {parseServiceFile.ExecStart}");
using var channel = UDSConnector.CreateChannel(); using var channel = UDSConnector.CreateChannel();
var client = new StartRpc.StartRpcClient(channel); var client = new StartRpc.StartRpcClient(channel);

View file

@ -8,11 +8,11 @@ var rootCommand = new RootCommand("Linux service manager written in C#");
rootCommand.AddCommand(initCommand); rootCommand.AddCommand(initCommand);
rootCommand.AddCommand(startCommand); rootCommand.AddCommand(startCommand);
initCommand.SetHandler((() => initCommand.SetHandler(() =>
{ {
new Init(); new Init();
})); });
startCommand.SetHandler((() => new Start())); startCommand.SetHandler(async () => await Start.StartAsync());
return await rootCommand.InvokeAsync(args); return await rootCommand.InvokeAsync(args);

View file

@ -0,0 +1,20 @@
using IniParser;
namespace netsd.Utils;
public class ServiceParser
{
public string? ExecStart { get; private set; }
public static async Task<ServiceParser> Parse(string ServiceInfoPath)
{
var readServiceFile = await File.ReadAllTextAsync(ServiceInfoPath);
var parser = new FileIniDataParser();
var serviceData = parser.Parser.Parse(readServiceFile);
var sv = new ServiceParser();
sv.ExecStart = serviceData["Service"]["ExecStart"];
return sv;
}
}

View file

@ -33,6 +33,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.50.0-pre1" /> <PackageReference Include="Grpc.AspNetCore" Version="2.50.0-pre1" />
<PackageReference Include="ini-parser" Version="3.4.0" />
<PackageReference Include="runtime.linux-musl-x64.Microsoft.DotNet.ILCompiler" Version="7.0.0" /> <PackageReference Include="runtime.linux-musl-x64.Microsoft.DotNet.ILCompiler" Version="7.0.0" />
<PackageReference Include="runtime.linux-x64.Microsoft.DotNet.ILCompiler" Version="7.0.0" /> <PackageReference Include="runtime.linux-x64.Microsoft.DotNet.ILCompiler" Version="7.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" /> <PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />