feat(server): 添加系统重启功能支持
添加后台任务支持用于处理系统重启请求,实现延迟进程终止机制, 允许系统安全地重启并在重启后自动恢复服务。 feat(frontend): 实现前端系统重启控制面板 在状态页面添加重启对话框组件,提供用户友好的重启确认界面, 包含重启状态监控和错误处理功能,确保用户可以安全重启系统。 docs(deployment): 更新部署指南添加URL协议要求说明 详细说明NANO_AUTHZ_URL和NANO_DEPLOY_URL环境变量必须包含 http://协议前缀的要求,添加常见错误示例和容器重建步骤, 帮助用户避免注册页面502错误问题。
This commit is contained in:
@ -12,17 +12,29 @@ import {
|
||||
Key,
|
||||
Loader2,
|
||||
} from 'lucide-react';
|
||||
import { getStatus } from '@/lib/api';
|
||||
import { getStatus, restartSystem } from '@/lib/api';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import type { SystemStatus } from '@/types';
|
||||
|
||||
export default function StatusPage() {
|
||||
const [status, setStatus] = useState<SystemStatus | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [restartDialogOpen, setRestartDialogOpen] = useState(false);
|
||||
const [restarting, setRestarting] = useState(false);
|
||||
const [restartError, setRestartError] = useState<string | null>(null);
|
||||
|
||||
const loadStatus = async () => {
|
||||
setLoading(true);
|
||||
@ -41,6 +53,36 @@ export default function StatusPage() {
|
||||
loadStatus();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!restarting) {
|
||||
return;
|
||||
}
|
||||
|
||||
const intervalId = window.setInterval(async () => {
|
||||
try {
|
||||
await getStatus();
|
||||
window.location.reload();
|
||||
} catch {
|
||||
// Ignore failures until the container is back.
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
return () => {
|
||||
window.clearInterval(intervalId);
|
||||
};
|
||||
}, [restarting]);
|
||||
|
||||
const handleRestart = async () => {
|
||||
setRestartError(null);
|
||||
try {
|
||||
await restartSystem();
|
||||
setRestartDialogOpen(false);
|
||||
setRestarting(true);
|
||||
} catch (err: any) {
|
||||
setRestartError(err.message || '重启失败');
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-20">
|
||||
@ -80,7 +122,7 @@ export default function StatusPage() {
|
||||
<div className="max-w-4xl mx-auto p-6 space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">系统状态</h1>
|
||||
<Button onClick={loadStatus} variant="outline" size="sm">
|
||||
<Button onClick={loadStatus} variant="outline" size="sm" disabled={restarting}>
|
||||
<RefreshCw className="w-4 h-4 mr-2" />
|
||||
刷新
|
||||
</Button>
|
||||
@ -94,17 +136,48 @@ export default function StatusPage() {
|
||||
系统信息
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<InfoRow
|
||||
label="配置"
|
||||
value={status.config_path}
|
||||
ok={status.config_exists}
|
||||
/>
|
||||
<InfoRow
|
||||
label="工作区"
|
||||
value={status.workspace}
|
||||
ok={status.workspace_exists}
|
||||
/>
|
||||
<CardContent>
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium">重启当前实例</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{restarting
|
||||
? '正在重启当前 docker,服务恢复后页面会自动刷新。'
|
||||
: '会重启当前 docker 容器。重启完成后需要重新登录。'}
|
||||
</p>
|
||||
{restartError ? (
|
||||
<p className="text-sm text-destructive">{restartError}</p>
|
||||
) : null}
|
||||
</div>
|
||||
<AlertDialog open={restartDialogOpen} onOpenChange={setRestartDialogOpen}>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => setRestartDialogOpen(true)}
|
||||
disabled={restarting}
|
||||
>
|
||||
{restarting ? (
|
||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||
) : (
|
||||
<RefreshCw className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
Restart
|
||||
</Button>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>确认重启当前实例?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
这会重启当前 docker 容器,页面会短暂不可用。由于当前登录态保存在内存里,重启完成后需要重新登录。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={restarting}>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleRestart} disabled={restarting}>
|
||||
{restarting ? '重启中...' : '确认 Restart'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user