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); } } public static async IAsyncEnumerable GetUnitLogs(string serviceName) { await foreach (var line in CommandExecutor.ExecuteCommandAsync("journalctl", $"--catalog --all --pager-end --follow --output=json --unit={serviceName}")) { yield return JsonSerializer.Deserialize(line)!; } } }