diff options
Diffstat (limited to '')
-rw-r--r-- | SystemdCtl/Controllers/UnitController.cs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/SystemdCtl/Controllers/UnitController.cs b/SystemdCtl/Controllers/UnitController.cs new file mode 100644 index 0000000..212df7d --- /dev/null +++ b/SystemdCtl/Controllers/UnitController.cs @@ -0,0 +1,29 @@ +using LibSystemdCli; +using LibSystemdCli.Models; +using Microsoft.AspNetCore.Mvc; + +namespace SystemdCtl.Controllers; +[ApiController] +[Route("/api/")] +public class UnitController : ControllerBase +{ + [HttpGet("listUnits")] + public async IAsyncEnumerable<SystemdUnitListItem> GetUnits() + { + await foreach (var unit in SystemdExecutor.GetUnits()) + { + yield return unit; + await Response.Body.FlushAsync(); + } + } + + [HttpGet("unit/{serviceName}/logs")] + public async IAsyncEnumerable<string> GetUnitLogs(string serviceName) + { + await foreach (var line in CommandExecutor.ExecuteCommandAsync("journalctl", $"-xaefu {serviceName}")) + { + yield return line; + await Response.Body.FlushAsync(); + } + } +} \ No newline at end of file |