3 Commits

Author SHA1 Message Date
70eab1f1b8 docs: 添加 README.md,记录正确的启动方式和端口规范
- 重要发现:服务被 OpenClaw 杀掉(SIGTERM)
- 解决方案:使用 nohup + disown 脱离进程树
- 更新所有项目的 start_cmd 为正确的启动方式
- 记录端口规范(19000-19100)
- 记录故障排查步骤
2026-04-15 09:59:39 +08:00
cc18d254a8 feat: 添加Cron列表快捷导航按钮 2026-04-14 10:49:08 +08:00
e7b5a1ce09 feat: Cron列表移至底部并添加概述分析 2026-04-14 10:40:09 +08:00
3 changed files with 280 additions and 41 deletions

131
README.md Normal file
View File

@@ -0,0 +1,131 @@
# 项目服务管理面板
统一管理所有 Web 服务项目,提供状态检测、启动/停止控制、日志查看等功能。
## 端口
- **服务端口**: 19013
- **访问地址**: http://localhost:19013
## 功能
- 项目列表展示(状态、端口、版本)
- 服务状态健康检测
- 启动/停止/重启控制
- 日志查看(实时滚动)
- Git 仓库链接
## 启动方式 ⭐
**重要:必须使用 `nohup + disown` 方式启动,脱离进程树!**
```bash
cd ~/.openclaw/workspace-coder/works/project-panel
nohup python3 app.py > logs/app.log 2>&1 & disown
```
### 为什么需要 disown
如果通过 OpenClaw 的 exec 启动服务,当 OpenClaw 清理进程时(如超时、重启),会发送 SIGTERM 杀掉所有子进程。
使用 `nohup + disown` 可以:
1. `nohup` - 让进程忽略 SIGHUP终端关闭信号
2. `disown` - 从 shell 进程树中移除,避免被连带杀掉
3. `> logs/app.log 2>&1` - 重定向输出到日志文件
### ❌ 错误方式
```bash
# 不要用这种方式(会被 OpenClaw 杀掉)
python3 app.py
```
### ✅ 正确方式
```bash
nohup python3 app.py > logs/app.log 2>&1 & disown
```
## 项目配置
项目配置在 `projects.json` 中,每个项目包含:
```json
{
"id": "project-id",
"name": "项目名称",
"ports": [19000],
"directory": "works/project-dir",
"start_cmd": "nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19000/api/health",
"admin_url": "http://localhost:19000/admin",
"git_repo": "http://192.168.2.8:12007/coder/project",
"version": "v1.0.0"
}
```
## 端口规范
所有 Web 服务必须使用 **19000-19100** 端口范围:
| 端口 | 项目 |
|------|------|
| 19000 | PDF翻译助手 V2 |
| 19001 | LLM Index RAG |
| 19009 | 碎片信息记录 |
| 19010 | ParamHub Python |
| 19013 | 项目服务管理面板(本服务) |
| 19014 | Xian Favor 收藏系统 |
| 19020 | AI对话系统 |
| 19007 | LLM Proxy |
| 19011 | 产品参数爬取系统 |
| 19004 | 技术论坛 |
| 19015 | 多智能体竞标调度系统 |
## API 接口
- `GET /api/projects` - 获取所有项目列表
- `GET /api/project/:id` - 获取单个项目详情
- `POST /api/project/:id/start` - 启动项目
- `POST /api/project/:id/stop` - 停止项目
- `POST /api/project/:id/restart` - 重启项目
- `GET /api/project/:id/logs` - 获取项目日志
## 监控
服务监控由 `service-monitor` 负责,每 20 分钟检查一次,发送邮件通知。
## 故障排查
### 服务频繁停止?
检查是否使用了正确的启动方式:
1. 确认使用了 `nohup + disown`
2. 确认日志目录存在:`mkdir -p logs/`
3. 查看日志:`cat logs/app.log`
### OpenClaw 杀进程?
如果日志突然停止(约凌晨 01:10可能是被 OpenClaw 清理进程杀掉了。
**证据:**
- OpenClaw 日志:`[tools] exec failed: Command aborted by signal SIGTERM`
- 服务日志最后记录时间01:09 左右
**解决:** 使用 `disown` 脱离进程树。
## Git 仓库
http://192.168.2.8:12007/coder/project-panel
## 更新日志
### v1.0.1
- 添加 README.md 文档
- 记录正确的启动方式nohup + disown
- 记录端口规范
### v1.0.0
- 项目服务管理面板
- 状态检测、启动/停止控制
- 日志查看

155
app.py
View File

@@ -235,7 +235,10 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
</h1>
<p class="text-gray-400 mt-1">统一管理所有项目和服务</p>
</div>
<div class="flex items-center gap-4">
<div class="flex items-center gap-3">
<button onclick="scrollToCrons()" class="btn bg-orange-600 hover:bg-orange-700 px-3 py-2 rounded-lg flex items-center gap-2">
<i class="ri-timer-line"></i> Cron 列表
</button>
<button onclick="refreshAll()" class="btn bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded-lg flex items-center gap-2">
<i class="ri-refresh-line"></i> 刷新状态
</button>
@@ -244,7 +247,7 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
</div>
<!-- 统计卡片 -->
<div class="grid grid-cols-2 md:grid-cols-5 gap-4 mb-8">
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">
<div class="card rounded-xl p-4">
<div class="flex items-center justify-between">
<div>
@@ -281,34 +284,6 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
<i class="ri-terminal-box-line text-3xl text-purple-400 opacity-50"></i>
</div>
</div>
<div class="card rounded-xl p-4">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-400 text-sm">系统Cron</p>
<p id="systemCronCount" class="text-2xl font-bold text-orange-400">-</p>
</div>
<i class="ri-timer-line text-3xl text-orange-400 opacity-50"></i>
</div>
</div>
</div>
<!-- 系统 Cron 列表 -->
<div class="card rounded-xl p-6 mb-8">
<div class="flex items-center justify-between mb-4">
<h2 class="text-xl font-bold flex items-center gap-2">
<i class="ri-timer-line text-orange-400"></i>
主机 Cron 列表
</h2>
<button onclick="loadCrons()" class="btn bg-orange-600 hover:bg-orange-700 px-3 py-1 rounded text-sm flex items-center gap-1">
<i class="ri-refresh-line"></i> 刷新
</button>
</div>
<div id="cronsList" class="space-y-3">
<div class="text-center py-8 text-gray-400">
<i class="ri-loader-4-line text-2xl animate-spin"></i>
<p class="mt-2 text-sm">加载中...</p>
</div>
</div>
</div>
<!-- 筛选器 -->
@@ -337,6 +312,33 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
<p class="mt-2">加载中...</p>
</div>
</div>
<!-- 系统 Cron 列表 -->
<div id="cronSection" class="card rounded-xl p-6 mt-8">
<div class="flex items-center justify-between mb-4">
<h2 class="text-xl font-bold flex items-center gap-2">
<i class="ri-timer-line text-orange-400"></i>
主机 Cron 列表
<span id="systemCronCount" class="text-sm text-gray-400 ml-2">-</span>
</h2>
<button onclick="loadCrons()" class="btn bg-orange-600 hover:bg-orange-700 px-3 py-1 rounded text-sm flex items-center gap-1">
<i class="ri-refresh-line"></i> 刷新
</button>
</div>
<!-- Cron 概述 -->
<div id="cronSummary" class="mb-4 p-4 bg-gray-800/50 rounded-lg border border-gray-700">
<div class="text-center py-4 text-gray-400 text-sm">加载中...</div>
</div>
<!-- Cron 详细列表 -->
<div id="cronsList" class="space-y-3">
<div class="text-center py-8 text-gray-400">
<i class="ri-loader-4-line text-2xl animate-spin"></i>
<p class="mt-2 text-sm">加载中...</p>
</div>
</div>
</div>
</div>
<!-- 日志模态框 -->
@@ -660,6 +662,13 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
loadProjects();
}
function scrollToCrons() {
const cronSection = document.getElementById('cronSection');
if (cronSection) {
cronSection.scrollIntoView({ behavior: 'smooth' });
}
}
// 初始化
loadProjects();
loadCrons();
@@ -686,6 +695,7 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
function renderCrons(crons) {
const list = document.getElementById('cronsList');
document.getElementById('systemCronCount').textContent = `${crons.length} 个`;
if (crons.length === 0) {
list.innerHTML = `
@@ -697,6 +707,54 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
return;
}
// 分类统计并生成概述
const userCrons = crons.filter(c => c.source === 'user');
const systemCrons = crons.filter(c => c.source === 'system');
const cronDCrons = crons.filter(c => c.source === 'cron.d');
// 分析用户任务用途
const userTaskTypes = analyzeUserCrons(userCrons);
// 生成概述
let summaryHtml = `
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="bg-blue-500/10 rounded-lg p-3 border border-blue-500/30">
<div class="flex items-center gap-2 mb-2">
<i class="ri-user-line text-blue-400"></i>
<span class="text-blue-400 font-medium">用户任务</span>
<span class="text-blue-300 text-sm">${userCrons.length} 个</span>
</div>
<div class="text-gray-300 text-sm space-y-1">
${userTaskTypes.map(t => `<div><span class="text-gray-400">${t.count}个</span> ${t.name}</div>`).join('')}
</div>
</div>
<div class="bg-red-500/10 rounded-lg p-3 border border-red-500/30">
<div class="flex items-center gap-2 mb-2">
<i class="ri-settings-line text-red-400"></i>
<span class="text-red-400 font-medium">系统任务</span>
<span class="text-red-300 text-sm">${systemCrons.length} 个</span>
</div>
<div class="text-gray-300 text-sm space-y-1">
<div><span class="text-gray-400">每小时</span> 执行 cron.hourly</div>
<div><span class="text-gray-400">每天</span> 执行 cron.daily</div>
<div><span class="text-gray-400">每周</span> 执行 cron.weekly</div>
<div><span class="text-gray-400">每月</span> 执行 cron.monthly</div>
</div>
</div>
<div class="bg-green-500/10 rounded-lg p-3 border border-green-500/30">
<div class="flex items-center gap-2 mb-2">
<i class="ri-file-list-line text-green-400"></i>
<span class="text-green-400 font-medium">cron.d</span>
<span class="text-green-300 text-sm">${cronDCrons.length} 个</span>
</div>
<div class="text-gray-300 text-sm space-y-1">
${cronDCrons.map(c => `<div><span class="text-gray-400">${c.file}</span> ${c.description || ''}</div>`).join('')}
</div>
</div>
</div>
`;
document.getElementById('cronSummary').innerHTML = summaryHtml;
const sourceColors = {
'user': { bg: 'bg-blue-500/20', text: 'text-blue-400', label: '用户' },
'system': { bg: 'bg-red-500/20', text: 'text-red-400', label: '系统' },
@@ -735,6 +793,43 @@ HTML_TEMPLATE = '''<!DOCTYPE html>
list.innerHTML = html;
}
function analyzeUserCrons(crons) {
const types = [];
// 服务监控
const monitors = crons.filter(c => c.command.includes('service-monitor') || c.command.includes('monitor.py') || c.command.includes('cpu-monitor') || c.command.includes('disk-monitor'));
if (monitors.length > 0) types.push({ name: '系统监控', count: monitors.length });
// 股票/板块相关
const stocks = crons.filter(c => c.command.includes('stock') || c.command.includes('board_monitor'));
if (stocks.length > 0) types.push({ name: 'A股数据/板块监控', count: stocks.length });
// 每日总结
const summaries = crons.filter(c => c.command.includes('daily-summary') || c.command.includes('summary'));
if (summaries.length > 0) types.push({ name: '每日总结', count: summaries.length });
// 清理脚本
const cleanups = crons.filter(c => c.command.includes('cleanup') || c.command.includes('clean'));
if (cleanups.length > 0) types.push({ name: '清理脚本', count: cleanups.length });
// 其他
const others = crons.filter(c =>
!c.command.includes('service-monitor') &&
!c.command.includes('monitor.py') &&
!c.command.includes('cpu-monitor') &&
!c.command.includes('disk-monitor') &&
!c.command.includes('stock') &&
!c.command.includes('board_monitor') &&
!c.command.includes('daily-summary') &&
!c.command.includes('summary') &&
!c.command.includes('cleanup') &&
!c.command.includes('clean')
);
if (others.length > 0) types.push({ name: '其他任务', count: others.length });
return types;
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;

View File

@@ -6,7 +6,7 @@
"type": "web",
"ports": [19000],
"directory": "works/pdf-translate-web-v2",
"start_cmd": "python3 app.py",
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19000/api/health",
"description": "英文PDF翻译中文网站支持用户系统、会员体系",
"admin_url": "http://localhost:19000/admin",
@@ -19,7 +19,7 @@
"type": "web",
"ports": [19001],
"directory": "works/llm-index-rag",
"start_cmd": "python3 app.py",
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19001/api/stats",
"description": "基于索引和搜索的知识检索系统",
"admin_url": "http://localhost:19001/settings",
@@ -32,7 +32,7 @@
"type": "web",
"ports": [19009],
"directory": "works/snippet-notes",
"start_cmd": "python3 app.py",
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19009/api/notes",
"description": "碎片信息记录工具AI自动生成标题",
"git_repo": null,
@@ -44,7 +44,7 @@
"type": "web",
"ports": [19010],
"directory": "works/param-hub-python",
"start_cmd": "python3 app.py",
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19010/api/stats",
"description": "AI大模型与硬件参数速查平台",
"admin_url": "http://localhost:19010/admin",
@@ -57,12 +57,12 @@
"type": "web",
"ports": [19020],
"directory": "works/ai-chat",
"start_cmd": "python3 main.py",
"start_cmd": "mkdir -p logs && nohup python3 main_v2.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19020/api/admin/stats",
"description": "网页端和Matrix端实时同步的AI聊天系统",
"admin_url": "http://localhost:19020/admin",
"git_repo": "http://192.168.2.8:12007/coder/ai-chat-system",
"version": "v1.0.0"
"version": "v2.5.4"
},
{
"id": "product-crawler",
@@ -70,7 +70,7 @@
"type": "web",
"ports": [19011],
"directory": "/home/xian/.openclaw/common/projects/product-crawler",
"start_cmd": "python3 app.py",
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19011/api/products",
"description": "自动从官网爬取产品参数信息",
"admin_url": "http://localhost:19011/admin",
@@ -83,13 +83,26 @@
"type": "web",
"ports": [19007],
"directory": "/home/xian/.openclaw/common/projects/llm-proxy",
"start_cmd": "python3 app.py",
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19007/health",
"description": "大模型API中转系统多提供商调度",
"admin_url": "http://localhost:19007/admin",
"git_repo": "http://192.168.2.8:12007/coder/llm-proxy",
"version": "v2.0.0"
},
{
"id": "project-panel",
"name": "项目服务管理面板",
"type": "web",
"ports": [19013],
"directory": "works/project-panel",
"start_cmd": "mkdir -p logs && nohup python3 app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19013/",
"description": "统一管理所有Web服务项目",
"admin_url": "http://localhost:19013",
"git_repo": "http://192.168.2.8:12007/coder/project-panel",
"version": "v1.0.1"
},
{
"id": "web-context-extension",
"name": "网页助手插件",
@@ -147,7 +160,7 @@
"type": "web",
"ports": [19014],
"directory": "works/xian-favor",
"start_cmd": "xian_favor serve --port 19014",
"start_cmd": "mkdir -p logs && nohup xian_favor serve --port 19014 > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19014/api/health",
"description": "文本笔记、链接收藏、待办事项管理系统",
"admin_url": "http://localhost:19014",
@@ -160,7 +173,7 @@
"type": "web",
"ports": [19015],
"directory": "works/multi-agent-bidding",
"start_cmd": "python3 -m app.app --port 19015",
"start_cmd": "mkdir -p logs && nohup python3 -m app.app --port 19015 > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19015/api/agents",
"description": "基于竞标机制的多智能体任务调度系统",
"admin_url": "http://localhost:19015",
@@ -173,7 +186,7 @@
"type": "web",
"ports": [19004],
"directory": "/home/xian/.openclaw/common/projects/tech-forum",
"start_cmd": "python3 backend/app.py",
"start_cmd": "mkdir -p logs && nohup python3 backend/app.py > logs/app.log 2>&1 & disown",
"health_url": "http://localhost:19004/api/health",
"description": "技术交流、工具分享、问答讨论社区",
"admin_url": "http://localhost:19004/admin",