feat: add restart server action for vendor and tenant
Vendor: POST /api/vendor/tenants/{id}/restart (platform:admin scope)
Tenant: POST /api/tenant/server/restart (tenant:manage scope)
Both call TenantProvisioner.stop() then start() on the server + UI
containers. Restart button on vendor TenantDetailPage (Actions card)
and tenant TenantDashboardPage (Server card). Allowed in any status
including PROVISIONING.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,14 @@ export function useTenantDashboard() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useRestartServer() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation<void, Error, void>({
|
||||
mutationFn: () => api.post('/tenant/server/restart'),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['tenant', 'dashboard'] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTenantLicense() {
|
||||
return useQuery<TenantLicenseData>({
|
||||
queryKey: ['tenant', 'license'],
|
||||
|
||||
@@ -54,6 +54,14 @@ export function useDeleteTenant() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useRestartServer() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation<void, Error, string>({
|
||||
mutationFn: (id) => api.post(`/vendor/tenants/${id}/restart`),
|
||||
onSuccess: (_, id) => qc.invalidateQueries({ queryKey: ['vendor', 'tenants', id] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRenewLicense() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation<LicenseResponse, Error, string>({
|
||||
|
||||
@@ -6,9 +6,10 @@ import {
|
||||
Card,
|
||||
KpiStrip,
|
||||
Spinner,
|
||||
useToast,
|
||||
} from '@cameleer/design-system';
|
||||
import { ExternalLink, Key, Settings } from 'lucide-react';
|
||||
import { useTenantDashboard } from '../../api/tenant-hooks';
|
||||
import { ExternalLink, Key, RefreshCw, Settings } from 'lucide-react';
|
||||
import { useTenantDashboard, useRestartServer } from '../../api/tenant-hooks';
|
||||
import { ServerStatusBadge } from '../../components/ServerStatusBadge';
|
||||
import { UsageIndicator } from '../../components/UsageIndicator';
|
||||
import { tierColor } from '../../utils/tier';
|
||||
@@ -26,7 +27,9 @@ function statusColor(status: string): 'success' | 'error' | 'warning' | 'auto' {
|
||||
|
||||
export function TenantDashboardPage() {
|
||||
const navigate = useNavigate();
|
||||
const { toast } = useToast();
|
||||
const { data, isLoading, isError } = useTenantDashboard();
|
||||
const restartServer = useRestartServer();
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -96,6 +99,23 @@ export function TenantDashboardPage() {
|
||||
<span className={styles.kvValueMono}>{data.serverEndpoint}</span>
|
||||
</div>
|
||||
)}
|
||||
<div style={{ paddingTop: 8 }}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await restartServer.mutateAsync();
|
||||
toast({ title: 'Server restarted', variant: 'success' });
|
||||
} catch (err) {
|
||||
toast({ title: 'Restart failed', description: String(err), variant: 'error' });
|
||||
}
|
||||
}}
|
||||
loading={restartServer.isPending}
|
||||
>
|
||||
<RefreshCw size={14} style={{ marginRight: 6 }} />
|
||||
Restart Server
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
|
||||
20
ui/src/pages/vendor/TenantDetailPage.tsx
vendored
20
ui/src/pages/vendor/TenantDetailPage.tsx
vendored
@@ -16,6 +16,7 @@ import {
|
||||
useActivateTenant,
|
||||
useDeleteTenant,
|
||||
useRenewLicense,
|
||||
useRestartServer,
|
||||
} from '../../api/vendor-hooks';
|
||||
import { ServerStatusBadge } from '../../components/ServerStatusBadge';
|
||||
import { tierColor } from '../../utils/tier';
|
||||
@@ -67,6 +68,7 @@ export function TenantDetailPage() {
|
||||
const activateTenant = useActivateTenant();
|
||||
const deleteTenant = useDeleteTenant();
|
||||
const renewLicense = useRenewLicense();
|
||||
const restartServer = useRestartServer();
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
@@ -105,6 +107,16 @@ export function TenantDetailPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRestart() {
|
||||
if (!id) return;
|
||||
try {
|
||||
await restartServer.mutateAsync(id);
|
||||
toast({ title: 'Server restarted', variant: 'success' });
|
||||
} catch (err) {
|
||||
toast({ title: 'Restart failed', description: String(err), variant: 'error' });
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
if (!id) return;
|
||||
try {
|
||||
@@ -247,6 +259,14 @@ export function TenantDetailPage() {
|
||||
{/* Actions */}
|
||||
<Card title="Actions">
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={handleRestart}
|
||||
loading={restartServer.isPending}
|
||||
>
|
||||
<RefreshCw size={14} style={{ marginRight: 6 }} />
|
||||
Restart Server
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={handleSuspendToggle}
|
||||
|
||||
Reference in New Issue
Block a user