feat(systemd): unit overview + journal viewer pages
- Add journalctl_recent command and scrum4me-web to whitelist in commands.yml.example - Add SYSTEMD_UNITS env var to .env.example - lib/parse-systemd.ts: parse activeState, subState, uptime, description - /app/systemd: server page reading SYSTEMD_UNITS, client list with 10s polling and status badges - /app/systemd/[unit]: server detail page, client component showing systemctl status + last 100 journal lines (polling 10s) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9e08a7c31f
commit
c12e36e0a4
7 changed files with 523 additions and 1 deletions
78
app/systemd/[unit]/page.tsx
Normal file
78
app/systemd/[unit]/page.tsx
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import Link from 'next/link'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { getCurrentUser } from '@/lib/session'
|
||||
import { execAgent } from '@/lib/agent-client'
|
||||
import UnitDetail from './_components/unit-detail'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ unit: string }>
|
||||
}
|
||||
|
||||
function getAllowedUnits(): string[] {
|
||||
return (process.env.SYSTEMD_UNITS ?? '')
|
||||
.split(',')
|
||||
.map((u) => u.trim())
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
export default async function SystemdUnitPage({ params }: Props) {
|
||||
const user = await getCurrentUser()
|
||||
if (!user) redirect('/login')
|
||||
|
||||
const { unit } = await params
|
||||
const unitName = decodeURIComponent(unit)
|
||||
|
||||
if (!getAllowedUnits().includes(unitName)) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background p-6">
|
||||
<div className="mx-auto max-w-6xl space-y-6">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href="/systemd" className="text-sm text-muted-foreground hover:text-foreground">
|
||||
← systemd Units
|
||||
</Link>
|
||||
</div>
|
||||
<div className="rounded-lg border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
||||
Unit "{unitName}" not found in SYSTEMD_UNITS.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
let initialStatusOutput = ''
|
||||
let initialJournalOutput = ''
|
||||
let initialError: string | null = null
|
||||
|
||||
try {
|
||||
const [statusOut, journalOut] = await Promise.all([
|
||||
execAgent('systemctl_status', [unitName]),
|
||||
execAgent('journalctl_recent', [unitName]),
|
||||
])
|
||||
initialStatusOutput = statusOut
|
||||
initialJournalOutput = journalOut
|
||||
} catch (err) {
|
||||
initialError = err instanceof Error ? err.message : 'Failed to fetch unit data'
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background p-6">
|
||||
<div className="mx-auto max-w-6xl space-y-6">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href="/systemd" className="text-sm text-muted-foreground hover:text-foreground">
|
||||
← systemd Units
|
||||
</Link>
|
||||
<span className="text-muted-foreground">/</span>
|
||||
<h1 className="text-2xl font-semibold tracking-tight font-mono">{unitName}</h1>
|
||||
</div>
|
||||
<UnitDetail
|
||||
unitName={unitName}
|
||||
initialStatusOutput={initialStatusOutput}
|
||||
initialJournalOutput={initialJournalOutput}
|
||||
initialError={initialError}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue