This document describes the recommended deployment, upgrade, backup and rollback flow for tg-monitor-v2.
- Linux server: Ubuntu 22.04/24.04, Debian 12, or compatible distribution.
- Python 3.11 or newer.
- Node.js 20 or newer.
- MySQL 8.x.
- A Telegram API ID and API Hash from https://my.telegram.org/apps.
- Optional proxy for Telegram connectivity.
git clone https://github.com/chu0119/tg-monitor-v2.git
cd tg-monitor-v2
cp .env.example .env
vim .env
bash install.shAfter installation:
./monitorctl.sh status
./health-check.shcd tg-monitor-v2
bash install-services.sh
sudo systemctl enable tgmonitor-backend.service
sudo systemctl enable tgmonitor-frontend.service
sudo systemctl start tgmonitor-backend.service
sudo systemctl start tgmonitor-frontend.serviceBefore upgrading, create a backup:
./monitorctl.sh backupThen update the code:
git fetch origin
git checkout main
git pull --ff-only origin main
cd frontend
npm ci
npm run build
cd ../backend
source venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart tgmonitor-backend.service
sudo systemctl restart tgmonitor-frontend.serviceVerify:
curl -f http://127.0.0.1:8000/health
curl -f http://127.0.0.1:3000/Data that must be backed up:
- MySQL database.
backend/sessions/Telegram session files..envruntime configuration.- Optional uploads and exports if used operationally.
Data that should not be committed to Git:
.envbackend/sessions/logs/exports/backups/frontend/dist/node_modules/
If a deployment fails:
git log --oneline -5
git checkout <known-good-commit>
cd frontend
npm ci
npm run build
sudo systemctl restart tgmonitor-backend.service
sudo systemctl restart tgmonitor-frontend.serviceIf data was changed, restore the database and session files from the backup created before upgrade.
- Set
JWT_SECRET_KEYto a long random value. - Restrict
CORS_ORIGINSto trusted domains in public deployments. - Protect
mainin GitHub and merge changes through Pull Requests. - Keep server
.envand Telegram session files off the repository. - Monitor
/healthand service logs after every upgrade.