Use absolute path for conf-file=; list all config files in UI

- EnsureManagedConfigHostedService: write conf-file=/absolute/path so
  dnsmasq finds the managed file regardless of CWD (e.g. systemd with CWD=/)
- Dnsmasq.razor: show Config files (load order) as single list with all
  paths (main, conf-dir, managed); fallback to Main/Managed when set unavailable
This commit is contained in:
2026-02-05 03:40:09 +10:00
parent beff128ed9
commit bda3305c5c
2 changed files with 20 additions and 13 deletions
+17 -12
View File
@@ -22,16 +22,15 @@ else if (_status != null)
{
<section class="page-section">
<h2 class="page-section-title">Service configuration</h2>
<ul class="list-unstyled small mb-0">
<li><strong>Main config:</strong> @(_status.MainConfigPath ?? "—") @(_status.MainConfigPathExists ? "✓" : "(missing)")</li>
<li><strong>Managed file:</strong> @(_status.ManagedFilePath ?? "—") @(_status.ManagedFilePathExists ? "✓" : "(not created yet)")</li>
</ul>
@if (_configSet != null && _configSet.Files?.Count > 0)
{
<p class="mb-1 mt-2"><strong>Config set (load order):</strong></p>
<ul class="list-unstyled small ms-2 mb-0">
<p class="mb-1"><strong>Config files (load order):</strong></p>
<ul class="list-unstyled small ms-2 mb-0">
@if (_configSet != null && _configSet.Files?.Count > 0)
{
@foreach (var f in _configSet.Files)
{
var isMain = string.Equals(f.Path, _status.MainConfigPath, StringComparison.Ordinal);
var isManaged = f.IsManaged;
var exists = isMain ? _status.MainConfigPathExists : (isManaged ? _status.ManagedFilePathExists : (bool?)null);
<li>
@if (f.IsManaged)
{
@@ -41,12 +40,18 @@ else if (_status != null)
{
<span class="badge bg-secondary me-1">@(f.Source.ToString().ToLowerInvariant())</span>
}
@f.FileName
<span class="text-muted">(@f.Path)</span>
@f.Path
@if (exists == true) { <text> ✓</text> }
@if (exists == false) { <text> @(isManaged ? "(not created yet)" : "(missing)")</text> }
</li>
}
</ul>
}
}
else
{
<li><strong>Main config:</strong> @(_status.MainConfigPath ?? "—") @(_status.MainConfigPathExists ? "✓" : "(missing)")</li>
<li><strong>Managed file:</strong> @(_status.ManagedFilePath ?? "—") @(_status.ManagedFilePathExists ? "✓" : "(not created yet)")</li>
}
</ul>
<EffectiveConfigSection Status="_status" />
@if (_status.ReloadCommandConfigured)
{
@@ -46,7 +46,8 @@ public class EnsureManagedConfigHostedService : IApplicationHostedService
var mainDir = Path.GetDirectoryName(mainFull) ?? "";
var managedPath = Path.GetFullPath(set.ManagedFilePath);
var managedDir = Path.GetDirectoryName(managedPath) ?? "";
var confFileLine = "conf-file=" + Path.GetRelativePath(mainDir, managedPath);
// Use absolute path so dnsmasq finds the file regardless of CWD (e.g. systemd may run with CWD=/).
var confFileLine = "conf-file=" + managedPath;
var lines = File.Exists(mainFull)
? (await File.ReadAllLinesAsync(mainFull, DnsmasqFileEncoding.Utf8NoBom, cancellationToken)).ToList()
@@ -62,6 +63,7 @@ public class EnsureManagedConfigHostedService : IApplicationHostedService
var value = trimmed.Length > 10 ? trimmed[10..].Trim() : "";
if (string.IsNullOrEmpty(value))
continue;
// Resolve relative to main config dir; absolute value is used as-is.
var resolved = Path.GetFullPath(Path.Combine(mainDir, value));
if (string.Equals(resolved, managedPath, StringComparison.Ordinal))
lines.RemoveAt(i);