summary refs log tree commit diff
path: root/SystemdCtl.Client
diff options
context:
space:
mode:
Diffstat (limited to 'SystemdCtl.Client')
-rw-r--r--SystemdCtl.Client/Pages/ServiceManage.razor81
-rw-r--r--SystemdCtl.Client/Pages/Services.razor1
-rw-r--r--SystemdCtl.Client/_Imports.razor2
3 files changed, 75 insertions, 9 deletions
diff --git a/SystemdCtl.Client/Pages/ServiceManage.razor b/SystemdCtl.Client/Pages/ServiceManage.razor
index c622833..851f1b6 100644
--- a/SystemdCtl.Client/Pages/ServiceManage.razor
+++ b/SystemdCtl.Client/Pages/ServiceManage.razor
@@ -2,7 +2,10 @@
 @using LibSystemdCli.Models

 @using LibSystemdCli

 @using System.Text.RegularExpressions

+@using ArcaneLibs.Extensions

 @using SystemdCtl.Client.Abstractions

+@using System.Diagnostics.Metrics

+@using System.Text.Json

 @* @attribute [StreamRendering] *@

 @rendermode InteractiveWebAssembly

 @inject NavigationManager NavigationManager

@@ -10,7 +13,26 @@
 

 <PageTitle>Manage @ServiceName</PageTitle>

 

-<h1>Manage @ServiceName</h1>

+<h1>Managing @ServiceName (@ServiceInfo?.Status)</h1>

+

+<div class="row">

+    <div class="col-12">

+        <h3>Actions</h3>

+        <div class="card">

+            <div class="card-body">

+                @if (ServiceInfo.IsRunning) {

+                    <LinkButton OnClick="@Stop">Stop</LinkButton>

+                    <LinkButton OnClick="@Restart">Restart</LinkButton>

+                    <LinkButton OnClick="@Kill">Kill</LinkButton>

+                }

+                else {

+                    <LinkButton OnClick="@Start">Start</LinkButton>

+                }

+            </div>

+        </div>

+    </div>

+</div>

+

 

 @* //simple log view *@

 <div class="row">

@@ -19,9 +41,14 @@
         <div class="card">

             <div class="card-body">

                 <pre>

-                    @foreach (var line in LogLines) {

-                        <span>@line</span><br/>

-                    }

+                    <table class="table table-sm table-striped">

+                        @foreach (var line in LogLines) {

+                            <tr>

+                                <td>@line.Exe.Split('/').Last()</td>

+                                <td>@line.Message</td>  

+                            </tr>

+                        }

+                    </table>

                 </pre>

             </div>

         </div>

@@ -36,6 +63,7 @@
     private static bool IsClient => !Environment.CommandLine.Contains("/");

 

     private List<SystemdJournalLogItem> LogLines { get; set; } = new();

+    private SystemdServiceData? ServiceInfo { get; set; } = new();

 

     protected override async Task OnInitializedAsync() {

         Console.WriteLine("OnInitializedAsync");

@@ -44,17 +72,36 @@
 

     private async Task Run() {

         if (!IsClient) return;

-

+        int history = 100;

         LogLines.Clear();

+        GetServiceDataTask();

         var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) };

-        var _items = Http.GetAsyncEnumerableFromJsonAsync<SystemdJournalLogItem>($"/api/unit/{ServiceName}/logs");

+        var jso = new JsonSerializerOptions() {

+            DefaultBufferSize = 1,

+            AllowTrailingCommas = true

+        };

+        var _items = Http.GetAsyncEnumerableFromJsonAsync<SystemdJournalLogItem>($"/api/unit/{ServiceName}/logs?contextLines={history}", jso);

         await foreach (var item in _items) {

+            // LogLines.RemoveAll(x=>x.SystemdInvocationId != item.SystemdInvocationId);

             LogLines.Add(item);

-            if (LogLines.Count > 100) LogLines.RemoveAt(0);

+            if (LogLines.Count > history) {

+                LogLines.RemoveAt(0);

+            }

+

             StateHasChanged();

         }

     }

 

+    private async Task GetServiceDataTask() {

+        if (!IsClient) return;

+        var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) };

+        while (true) {

+            ServiceInfo = await Http.GetFromJsonAsync<SystemdServiceData>($"/api/unit/{ServiceName}/data");

+            StateHasChanged();

+            await Task.Delay(TimeSpan.FromSeconds(5));

+        }

+    }

+

     private string Capitalize(string input) {

         return input switch {

             null => throw new ArgumentNullException(nameof(input)),

@@ -63,4 +110,24 @@
         };

     }

 

+    private async Task Start() {

+        var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) };

+        await Http.GetAsync($"/api/unit/{ServiceName}/start", null);

+    }

+

+    private async Task Stop() {

+        var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) };

+        await Http.GetAsync($"/api/unit/{ServiceName}/stop", null);

+    }

+

+    private async Task Restart() {

+        var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) };

+        await Http.GetAsync($"/api/unit/{ServiceName}/restart", null);

+    }

+

+    private async Task Kill() {

+        var Http = new StreamingHttpClient() { BaseAddress = new Uri(NavigationManager.BaseUri) };

+        await Http.GetAsync($"/api/unit/{ServiceName}/kill", null);

+    }

+

 }
\ No newline at end of file
diff --git a/SystemdCtl.Client/Pages/Services.razor b/SystemdCtl.Client/Pages/Services.razor
index d0f67a7..f2e8bb9 100644
--- a/SystemdCtl.Client/Pages/Services.razor
+++ b/SystemdCtl.Client/Pages/Services.razor
@@ -2,7 +2,6 @@
 @using LibSystemdCli.Models

 @using System.Text.RegularExpressions

 @using SystemdCtl.Client.Abstractions

-@using ArcaneLibs.Blazor.Components

 @* @attribute [StreamRendering] *@

 @rendermode InteractiveWebAssembly

 @inject NavigationManager NavigationManager

diff --git a/SystemdCtl.Client/_Imports.razor b/SystemdCtl.Client/_Imports.razor
index 3da583a..71d1c80 100644
--- a/SystemdCtl.Client/_Imports.razor
+++ b/SystemdCtl.Client/_Imports.razor
@@ -7,4 +7,4 @@
 @using Microsoft.AspNetCore.Components.Web.Virtualization

 @using Microsoft.JSInterop

 @using SystemdCtl.Client

-

+@using ArcaneLibs.Blazor.Components