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 (
← systemd Units
Unit "{unitName}" not found in SYSTEMD_UNITS.
) } 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 (
← systemd Units /

{unitName}

) }