summary refs log tree commit diff
path: root/SystemdCtl/Controllers
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 /SystemdCtl/Controllers
downloadSystemdCtl-43e06f4b1b7ead9f8cc97fe547eb49d51f341486.tar.xz
Initial commit
Diffstat (limited to 'SystemdCtl/Controllers')
-rw-r--r--SystemdCtl/Controllers/UnitController.cs29
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