summary refs log tree commit diff
path: root/SystemdCtl
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-01-20 11:34:00 +0100
committerRory& <root@rory.gay>2024-01-20 11:34:00 +0100
commit8c15a67166e545169216eee8be7c44acf03a27cb (patch)
tree2667e4899e14bf66e2d31b7d33978d7d2dd679b4 /SystemdCtl
parentJson logs (diff)
downloadSystemdCtl-8c15a67166e545169216eee8be7c44acf03a27cb.tar.xz
Add actions and unit data
Diffstat (limited to 'SystemdCtl')
-rw-r--r--SystemdCtl/Controllers/UnitController.cs26
-rw-r--r--SystemdCtl/Program.cs3
2 files changed, 26 insertions, 3 deletions
diff --git a/SystemdCtl/Controllers/UnitController.cs b/SystemdCtl/Controllers/UnitController.cs
index 00916bf..a128584 100644
--- a/SystemdCtl/Controllers/UnitController.cs
+++ b/SystemdCtl/Controllers/UnitController.cs
@@ -18,12 +18,34 @@ public class UnitController : ControllerBase
     }
     
     [HttpGet("unit/{serviceName}/logs")]
-    public async IAsyncEnumerable<SystemdJournalLogItem> GetUnitLogs(string serviceName)
+    public async IAsyncEnumerable<SystemdJournalLogItem> GetUnitLogs(string serviceName, [FromQuery] int contextLines = 100)
     {
-        await foreach (var log in SystemdExecutor.GetUnitLogs(serviceName))
+        await foreach (var log in SystemdExecutor.GetUnitLogs(serviceName, contextLines: contextLines))
         {
+            Console.WriteLine(log.Message);
             yield return log;
             await Response.Body.FlushAsync();
         }
     }
+    
+    [HttpGet("unit/{serviceName}/data")]
+    public Task<SystemdServiceData> GetUnitData(string serviceName) => SystemdExecutor.GetUnitData(serviceName);
+    
+    [HttpGet("unit/{serviceName}/start")]
+    public Task StartUnit(string serviceName) => CommandExecutor.ExecuteCommand("systemctl", $"start {serviceName}");
+    
+    [HttpGet("unit/{serviceName}/stop")]
+    public Task StopUnit(string serviceName) => CommandExecutor.ExecuteCommand("systemctl", $"stop {serviceName}");
+    
+    [HttpGet("unit/{serviceName}/restart")]
+    public Task RestartUnit(string serviceName) => CommandExecutor.ExecuteCommand("systemctl", $"restart {serviceName}");
+    
+    [HttpGet("unit/{serviceName}/reload")]
+    public Task ReloadUnit(string serviceName) => CommandExecutor.ExecuteCommand("systemctl", $"reload {serviceName}");
+    
+    [HttpGet("unit/{serviceName}/enable")]
+    public Task EnableUnit(string serviceName) => CommandExecutor.ExecuteCommand("systemctl", $"enable {serviceName}");
+    
+    [HttpGet("unit/{serviceName}/disable")]
+    public Task DisableUnit(string serviceName) => CommandExecutor.ExecuteCommand("systemctl", $"disable {serviceName}");
 }
\ No newline at end of file
diff --git a/SystemdCtl/Program.cs b/SystemdCtl/Program.cs
index c399d31..f0f01c3 100644
--- a/SystemdCtl/Program.cs
+++ b/SystemdCtl/Program.cs
@@ -10,7 +10,8 @@ builder.Services.AddRazorComponents()
 builder.Services.AddControllers().AddJsonOptions(options =>

 {

     options.JsonSerializerOptions.WriteIndented = true;

-    options.JsonSerializerOptions.DefaultBufferSize = 128;

+    options.JsonSerializerOptions.DefaultBufferSize = 1;

+    options.JsonSerializerOptions.AllowTrailingCommas = true;

 });

 

 var app = builder.Build();