From 43e06f4b1b7ead9f8cc97fe547eb49d51f341486 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 20 Jan 2024 08:34:32 +0100 Subject: Initial commit --- LibSystemdCli/SystemdExecutor.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 LibSystemdCli/SystemdExecutor.cs (limited to 'LibSystemdCli/SystemdExecutor.cs') diff --git a/LibSystemdCli/SystemdExecutor.cs b/LibSystemdCli/SystemdExecutor.cs new file mode 100644 index 0000000..eb6dfc9 --- /dev/null +++ b/LibSystemdCli/SystemdExecutor.cs @@ -0,0 +1,31 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using LibSystemdCli.Models; + +namespace LibSystemdCli; + +public class SystemdExecutor +{ + public static async IAsyncEnumerable GetUnits() + { + var output = await CommandExecutor.ExecuteCommand("systemctl", "list-units --all --no-legend --no-pager --no-legend -o json-pretty"); + + var data = JsonSerializer.Deserialize>(output); + + foreach (var unit in data) + { + try + { + var fragmentOutput = await CommandExecutor.ExecuteCommand("systemctl", $"show -P FragmentPath --no-pager --no-legend -- {unit.Unit} "); + // Console.WriteLine(fragmentOutput); + unit.FragmentPaths = fragmentOutput.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList(); + } + catch + { + } + + yield return unit; + // await Task.Delay(100); + } + } +} \ No newline at end of file -- cgit 1.4.1