summary refs log tree commit diff
path: root/SystemdCtl/Controllers/UnitController.cs
blob: 00916bf5c2a4c9a2bf140951190e475c195f75cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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<SystemdJournalLogItem> GetUnitLogs(string serviceName)
    {
        await foreach (var log in SystemdExecutor.GetUnitLogs(serviceName))
        {
            yield return log;
            await Response.Body.FlushAsync();
        }
    }
}