From 43e06f4b1b7ead9f8cc97fe547eb49d51f341486 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 20 Jan 2024 08:34:32 +0100 Subject: Initial commit --- SystemdCtl/Controllers/UnitController.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SystemdCtl/Controllers/UnitController.cs (limited to 'SystemdCtl/Controllers') 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 GetUnits() + { + await foreach (var unit in SystemdExecutor.GetUnits()) + { + yield return unit; + await Response.Body.FlushAsync(); + } + } + + [HttpGet("unit/{serviceName}/logs")] + public async IAsyncEnumerable 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 -- cgit 1.5.1