add simple service file parsing
This commit is contained in:
parent
84ac974427
commit
71c50ded5c
4 changed files with 28 additions and 5 deletions
|
@ -3,10 +3,12 @@ using StartGrpc;
|
|||
|
||||
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();
|
||||
|
||||
var client = new StartRpc.StartRpcClient(channel);
|
||||
|
|
|
@ -8,11 +8,11 @@ var rootCommand = new RootCommand("Linux service manager written in C#");
|
|||
rootCommand.AddCommand(initCommand);
|
||||
rootCommand.AddCommand(startCommand);
|
||||
|
||||
initCommand.SetHandler((() =>
|
||||
initCommand.SetHandler(() =>
|
||||
{
|
||||
new Init();
|
||||
}));
|
||||
});
|
||||
|
||||
startCommand.SetHandler((() => new Start()));
|
||||
startCommand.SetHandler(async () => await Start.StartAsync());
|
||||
|
||||
return await rootCommand.InvokeAsync(args);
|
||||
|
|
20
netsd/Utils/ServiceParser.cs
Normal file
20
netsd/Utils/ServiceParser.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<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-x64.Microsoft.DotNet.ILCompiler" Version="7.0.0" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||
|
|
Reference in a new issue