Chạy Bestie ở nền
Dùng background runtime khi bạn muốn Telegram, Zalo hoặc cron schedules tiếp tục chạy sau khi terminal hiện tại thoát. Bestie hỗ trợ hai cách chạy local:
bestie daemon ...khởi động và theo dõi các process tách rời từ CLI.bestie service ...cài user-level startup integration cho platform hiện tại.
Dùng bestie daemon ... khi cần điều khiển thủ công, debug local hoặc start/stop từng runtime target. Dùng bestie service ... khi bạn muốn Bestie tự chạy lúc đăng nhập hoặc được hệ điều hành quản lý.
Phù hợp để debug, chạy trên hệ không phải Linux và start/stop từng runtime target.
Phù hợp cho local install chạy lâu dài, cần tự chạy lại sau login hoặc restart.
Telegram, Zalo, cron và local UI có thể chạy qua platform startup integration.
Chỉ chạy một background mode cho cùng một target để tránh polling hoặc cron bị chạy trùng.
Bestie quản lý ba runtime target:
telegramchạybestie channels telegram.zalochạybestie channels zalo.cronchạybestie cron run.
Lệnh daemon dùng --channel telegram|zalo|cron|all. Nếu không truyền --channel, daemon command mặc định nhắm tới Telegram.
Trước khi chạy
Phần tiêu đề “Trước khi chạy”Hoàn tất setup cho từng kênh bạn muốn chạy:
- Telegram cần
channels.telegram.enabled, owner id hoặc username, và giá trị env chứa Telegram bot token. - Zalo cần
channels.zalo.enabled, owner id, và giá trị env chứa Zalo bot token. - Cron cần ít nhất một schedule nếu bạn mong có job được chạy.
Chạy Doctor trước khi bật process lâu dài:
bestie doctorbestie channels doctorNếu kênh chưa cấu hình đúng, daemon vẫn có thể start, nhưng process của kênh sẽ ghi lỗi vào daemon log.
Chọn một background mode cho vận hành bình thường. Chạy đồng thời manual daemon và user service cho cùng một target có thể tạo polling hoặc cron trùng lặp.
Start daemon
Phần tiêu đề “Start daemon”Start một kênh:
bestie daemon start --channel telegrambestie daemon start --channel zalobestie daemon start --channel cronStart toàn bộ daemon channel được hỗ trợ:
bestie daemon start --channel allKhi start, Bestie ghi daemon state trong runtime app directory và in process id cùng log path. Mỗi target có state file và log file riêng, ví dụ daemon-telegram.json và daemon-telegram.log, daemon-zalo.json và daemon-zalo.log, hoặc daemon-cron.json và daemon-cron.log.
Start một daemon đang chạy sẽ không tạo bản thứ hai. Bestie sẽ báo process id hiện có.
Kiểm tra trạng thái
Phần tiêu đề “Kiểm tra trạng thái”Kiểm tra daemon Telegram mặc định:
bestie daemon statusKiểm tra tất cả daemon channel:
bestie daemon status --channel allStatus có thể báo:
runningkhi process id được ghi lại vẫn đang chạy.stalekhi Bestie có daemon state file nhưng process không còn chạy.stoppedkhi kênh đó chưa có daemon state.
Nếu status là stale, restart daemon để xóa state cũ và tạo process nền mới.
Với state daemon Telegram kiểu cũ, Bestie vẫn nhận file legacy daemon.json để status, stop và restart có thể dọn qua command hiện tại.
Restart sau khi đổi config
Phần tiêu đề “Restart sau khi đổi config”Restart kênh sau khi đổi config, token, voice setting hoặc cron schedule:
bestie daemon restart --channel telegrambestie daemon restart --channel zalobestie daemon restart --channel cronRestart mọi daemon channel:
bestie daemon restart --channel allRestart gửi SIGTERM tới process được ghi lại, đợi process thoát, xóa state file cũ rồi start process mới. Nếu process id đã bị tái sử dụng bởi command khác, Bestie xóa state stale thay vì kill process không liên quan.
Stop daemon
Phần tiêu đề “Stop daemon”Stop một kênh:
bestie daemon stop --channel telegramStop mọi daemon channel:
bestie daemon stop --channel allBestie đợi tối đa 30 giây để process dừng. Trước khi stop process được ghi lại, Bestie kiểm tra command line của process khi nền tảng hỗ trợ. Nếu pid hiện thuộc về thứ khác, Bestie xóa daemon state stale thay vì kill process đó. Nếu process Bestie không thoát kịp, command báo timeout và giữ state để bạn tiếp tục troubleshoot.
Cài user service
Phần tiêu đề “Cài user service”Bestie có thể tạo user-level startup integration. Tính năng này thuộc lệnh bestie service, không phải installer và không phải bestie daemon:
bestie service installTrên Linux, lệnh này ghi bestie.service vào user systemd config directory, xóa các per-channel service file cũ nếu có, rồi chạy:
systemctl --user daemon-reloadsystemctl --user enable --now bestie.serviceLinux service unit chạy bestie service run ở foreground với Restart=on-failure, RestartSec=5 và TimeoutStopSec=45. Khi start, Bestie chọn installable targets từ local config:
cronluôn được include mặc định.telegramchỉ được include khi Telegram channel bật và giá trị env của bot token đã có.zalochỉ được include khi Zalo channel bật và giá trị env của bot token đã có.
Kiểm tra status hint của service command:
bestie service statusTrên macOS, bestie service install ghi launchd LaunchAgents cho service runtime và local UI. Trên Windows, lệnh này ghi Bestie.lnk và Bestie.ico vào Startup folder của user; shortcut start bestie daemon start --channel all, đồng thời start Web UI companion daemon.
Restart user service sau khi đổi channel, token, voice, cron hoặc UI config:
bestie service restartGỡ service:
bestie service uninstallTrên Linux, uninstall disable và stop bestie.service, xóa service file rồi reload user systemd daemon. Nó cũng xóa các per-channel service file cũ tên bestie-telegram.service, bestie-zalo.service và bestie-cron.service nếu tồn tại. Service unit bị thiếu sẽ được bỏ qua khi uninstall. Trên macOS, uninstall unload và xóa Bestie LaunchAgents. Trên Windows, lệnh này xóa Startup shortcut và icon.
Không tự chạy bestie service run cho nhu cầu thường ngày. Đây là hidden foreground command được platform service integration dùng.
Đọc logs
Phần tiêu đề “Đọc logs”Daemon command in log path khi process start hoặc khi status tìm thấy running/stale state. Dùng path đó để debug lỗi khởi động kênh.
Với user service, dùng status hint Bestie in ra. Trên Linux, xem systemd journal của bestie.service; trên macOS, xem launchd logs; trên Windows, kiểm tra Startup shortcut và Bestie daemon logs.
Bạn cũng có thể xem log Bestie đã redacted gần đây bằng tools command:
bestie tools logs --lines 20Không paste bot token, provider key, .bestie/.env hoặc raw daemon log vào public issue tracker. Logs có thể chứa ngữ cảnh vận hành dù secret được thiết kế để nằm trong env files.
Cách sửa lỗi thường gặp
Phần tiêu đề “Cách sửa lỗi thường gặp”Daemon start nhưng kênh không phản hồi
Phần tiêu đề “Daemon start nhưng kênh không phản hồi”Chạy kênh trực tiếp một lần để thấy lỗi ngay trong terminal:
bestie channels telegram --oncebestie channels zalo --onceSau đó kiểm tra channel diagnostics:
bestie channels doctor --channel telegram --connectbestie channels doctor --channel zalo --connectStatus báo stale
Phần tiêu đề “Status báo stale”Restart kênh bị ảnh hưởng:
bestie daemon restart --channel telegramBestie xóa stale state trong lúc restart và ghi state file mới cho process thay thế.
bestie daemon install bị từ chối
Phần tiêu đề “bestie daemon install bị từ chối”Startup integration đã chuyển sang service command. Dùng:
bestie service installbestie service statusManual daemon lifecycle command chỉ gồm:
bestie daemon start --channel allbestie daemon stop --channel allbestie daemon restart --channel allbestie daemon status --channel allService start nhưng chỉ cron hoặc UI chạy
Phần tiêu đề “Service start nhưng chỉ cron hoặc UI chạy”Bestie luôn include cron service target trong service runtime. Telegram và Zalo service target bị skip nếu kênh chưa bật hoặc giá trị env của bot token chưa có. Trên macOS và Windows, local UI cũng có thể được platform integration start.
Kiểm tra channel setup và env values, sau đó restart service:
bestie channels doctor --channel telegram --connectbestie channels doctor --channel zalo --connectbestie service restartStop bị timeout
Phần tiêu đề “Stop bị timeout”Nếu stop báo daemon pid không dừng trong timeout, xem log path từ status, rồi chỉ stop process thủ công sau khi xác nhận pid vẫn thuộc về Bestie.
bestie daemon status --channel telegram