Files
JianMiauandClaude Fable 5 41ab88abbb 新增 Windows 版 crontab-ui
摘要:
從 macOS 版移植的網頁排程與程序管理面板,可在 Windows 原生執行。

說明:
- Windows 無系統 cron,改為本地檔案 crontab.txt 儲存 + 伺服器內建排程器執行(支援五欄位語法與 @ 巨集,@reboot 於伺服器啟動時執行)
- lsof → netstat -ano、ps aux → PowerShell Get-CimInstance、kill → taskkill
- PM2 / Docker 指令跨平台,維持不變
- 前端:PM2 頁籤設為首頁;script 路徑僅顯示檔名,滑鼠停留顯示完整路徑;port 連結改用目前主機名

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-13 12:30:30 +08:00

81 lines
2.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Crontab UI (Windows)
網頁版的排程與程序管理面板,移植自 macOS 版 crontab-ui,改為在 Windows 上原生執行。
單一 Node.js 伺服器(Express+ 單一 HTML 前端,無框架、無建置步驟。
## 功能
| 頁籤 | 說明 |
|---|---|
| 🟢 PM2(首頁) | 列出 PM2 程序(狀態、PID、CPU、記憶體、重啟次數、監聽 port),可啟動/停止/重啟/刪除 |
| ⏰ Crontab | 以 cron 語法管理排程任務,支援新增、編輯、啟用/停用、刪除、任務備註(label) |
| 🟡 Node.js | 列出系統上所有 node / bun 程序,可結束程序(taskkill |
| 🐳 Docker | 列出容器並可啟動/停止/重啟(需安裝 Docker) |
| 📋 Log | 瀏覽 log 目錄下的 `.log` 檔案,支援 tail 與自動刷新 |
## 安裝與執行
需求:Node.js 18+、Windows
```bash
npm install
node server.js
```
開啟 <http://localhost:3789>
### 用 PM2 背景常駐(建議)
```bash
npm install -g pm2 pm2-windows-startup
pm2 start server.js --name crontab-ui
pm2 save
pm2-startup install # 登入 Windows 後自動啟動
```
## 環境變數
| 變數 | 預設值 | 說明 |
|---|---|---|
| `PORT` | `3789` | 網頁伺服器 port |
| `CRONTAB_FILE` | `<專案目錄>\crontab.txt` | 排程任務儲存檔 |
| `LOG_DIR` | `<專案目錄>\logs` | Log 頁籤讀取的目錄,排程執行紀錄 `cron.log` 也寫在這裡 |
## 排程機制(與 macOS 版的差異)
Windows 沒有系統 cron,本版本改為:
- 任務儲存在本地檔案 `crontab.txt`(格式與 crontab 完全相同,含 `#` 停用與備註行)
- 伺服器**內建排程器**,每分鐘比對一次並以 `cmd.exe` 執行到期的指令
- 執行結果(stdout / stderr / 錯誤)寫入 `logs\cron.log`,可直接在 UI 的 Log 頁籤查看
支援的 cron 語法:
- 五欄位:`分 時 日 月 週`,可用 `*`、清單 `1,15`、範圍 `9-17`、步進 `*/5`、組合 `1-5/2`
- 巨集:`@hourly``@daily``@midnight``@weekly``@monthly``@yearly``@annually`
- `@reboot`:改為「伺服器啟動時」執行一次
- 日與週同時指定時,符合其一即執行(標準 cron 行為)
> ⚠️ 排程器跟著伺服器運行:伺服器停止期間的任務不會補跑。請搭配 PM2 常駐。
其他系統層替換:
| 功能 | macOS 版 | Windows 版 |
|---|---|---|
| 排程儲存/執行 | 系統 `crontab` + cron | 本地檔案 + 內建排程器 |
| 監聽 port 偵測 | `lsof` | `netstat -ano` |
| 程序清單 | `ps aux` | PowerShell `Get-CimInstance Win32_Process` |
| 結束程序 | `kill -15` / `-9` | `taskkill` / `taskkill /F /T` |
## 專案結構
```
crontab-ui/
├── server.js # Express API + 內建 cron 排程器
├── public/
│ └── index.html # 前端(單檔,無建置)
├── crontab.txt # 排程任務(執行時自動建立,不進版控)
└── logs/ # log 目錄(不進版控)
```