summary refs log tree commit diff
path: root/LibSystemdCli/SystemdExecutor.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-01-20 08:34:32 +0100
committerRory& <root@rory.gay>2024-01-20 08:34:32 +0100
commit43e06f4b1b7ead9f8cc97fe547eb49d51f341486 (patch)
treeb700ba441320e0f3944c398080cadd296f03ef07 /LibSystemdCli/SystemdExecutor.cs
downloadSystemdCtl-43e06f4b1b7ead9f8cc97fe547eb49d51f341486.tar.xz
Initial commit
Diffstat (limited to 'LibSystemdCli/SystemdExecutor.cs')
-rw-r--r--LibSystemdCli/SystemdExecutor.cs31
1 files changed, 31 insertions, 0 deletions
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<SystemdUnitListItem> GetUnits()
+    {
+        var output = await CommandExecutor.ExecuteCommand("systemctl", "list-units --all --no-legend --no-pager --no-legend -o json-pretty");
+        
+        var data = JsonSerializer.Deserialize<List<SystemdUnitListItem>>(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