323 lines
6.8 KiB
Markdown
323 lines
6.8 KiB
Markdown
# 📁 Deployment Scripts - Index
|
|
|
|
Structura completă de scripturi pentru deployment Windows Service.
|
|
|
|
## 📂 Structura Directoarelor
|
|
|
|
```
|
|
deployment/windows/
|
|
├── README.md # Documentație completă
|
|
├── QUICK_START.md # Ghid rapid 5 minute
|
|
├── INDEX.md # Acest fișier
|
|
├── scripts/ # Scripturi PowerShell
|
|
│ ├── menu.ps1 # ⭐ Meniu interactiv (START HERE)
|
|
│ ├── deploy.ps1 # 🚀 Deployment complet
|
|
│ ├── install_service.ps1 # Instalare serviciu Windows
|
|
│ ├── uninstall_service.ps1 # Dezinstalare serviciu
|
|
│ ├── restart_service.ps1 # Restart rapid serviciu
|
|
│ ├── status.ps1 # Status serviciu și logs
|
|
│ └── view_logs.ps1 # Viewer logs interactiv
|
|
└── tools/ # Binare (auto-download)
|
|
├── .gitignore
|
|
└── nssm.exe # Downloaded by install_service
|
|
```
|
|
|
|
---
|
|
|
|
## 🚦 Quick Navigation
|
|
|
|
| Dacă vrei să... | Rulează |
|
|
|-----------------|---------|
|
|
| **⭐ Meniu interactiv** | `menu.ps1` |
|
|
| **🆕 Instalezi prima dată** | `deploy.ps1` |
|
|
| **📊 Verifici statusul** | `status.ps1` |
|
|
| **🔄 Restarți serviciul** | `restart_service.ps1` |
|
|
| **📝 Vezi logs-uri** | `view_logs.ps1` |
|
|
| **🗑️ Dezinstalezi** | `uninstall_service.ps1` |
|
|
| **📖 Citești ghidul** | `README.md` sau `QUICK_START.md` |
|
|
|
|
**💡 TIP:** Folosește `menu.ps1` pentru o experiență user-friendly!
|
|
|
|
---
|
|
|
|
## 📜 Descriere Scripturi
|
|
|
|
### 🚀 `deploy.bat` (Main Script)
|
|
|
|
**Scop:** Deployment complet one-click
|
|
|
|
**Ce face:**
|
|
1. Verifică Python și dependențe
|
|
2. Configurează `.env` (dacă nu există)
|
|
3. Instalează requirements Python
|
|
4. Instalează browsere Playwright
|
|
5. Creează și pornește serviciul Windows
|
|
6. Verifică status final
|
|
|
|
**Rulare:**
|
|
```batch
|
|
cd deployment\windows\scripts
|
|
deploy.bat
|
|
```
|
|
|
|
**Durată:** 2-5 minute (prima dată)
|
|
|
|
**Note:**
|
|
- Necesită Administrator
|
|
- Interactiv (așteaptă configurare `.env`)
|
|
|
|
---
|
|
|
|
### ⚙️ `install_service.bat`
|
|
|
|
**Scop:** Instalează DOAR serviciul Windows (fără dependențe)
|
|
|
|
**Ce face:**
|
|
1. Descarcă NSSM (dacă lipsește)
|
|
2. Verifică `.env` și bot script
|
|
3. Instalează serviciu cu NSSM
|
|
4. Configurează logging, restart policy
|
|
5. Pornește serviciul
|
|
|
|
**Rulare:**
|
|
```batch
|
|
install_service.bat
|
|
```
|
|
|
|
**Use case:** După ce ai instalat manual Python + requirements
|
|
|
|
---
|
|
|
|
### 🗑️ `uninstall_service.bat`
|
|
|
|
**Scop:** Elimină serviciul din Windows
|
|
|
|
**Ce face:**
|
|
1. Oprește serviciul (dacă rulează)
|
|
2. Dezinstalează cu NSSM
|
|
3. Verifică eliminare completă
|
|
|
|
**Rulare:**
|
|
```batch
|
|
uninstall_service.bat
|
|
```
|
|
|
|
**Note:**
|
|
- NU șterge fișiere proiect
|
|
- NU șterge logs
|
|
- Doar elimină serviciul din registry
|
|
|
|
---
|
|
|
|
### 🔄 `restart_service.bat`
|
|
|
|
**Scop:** Restart rapid serviciu (după modificări cod)
|
|
|
|
**Ce face:**
|
|
1. Stop serviciu
|
|
2. Wait 2 secunde
|
|
3. Start serviciu
|
|
4. Verifică status
|
|
|
|
**Rulare:**
|
|
```batch
|
|
restart_service.bat
|
|
```
|
|
|
|
**Use case:** După `git pull` sau modificări `.env`
|
|
|
|
---
|
|
|
|
### 📊 `status.bat`
|
|
|
|
**Scop:** Status detaliat serviciu + logs
|
|
|
|
**Ce face:**
|
|
1. Verifică dacă serviciul există
|
|
2. Afișează status detaliat (`sc query`)
|
|
3. Afișează configurație (`sc qc`)
|
|
4. Afișează ultimele 10 linii din logs
|
|
5. Afișează comenzi utile
|
|
|
|
**Rulare:**
|
|
```batch
|
|
status.bat
|
|
```
|
|
|
|
**Use case:** Quick health check
|
|
|
|
---
|
|
|
|
### 📝 `view_logs.bat`
|
|
|
|
**Scop:** Viewer interactiv logs
|
|
|
|
**Meniu:**
|
|
1. View stdout (toate logs)
|
|
2. View stderr (doar erori)
|
|
3. Tail stdout (live updates)
|
|
4. Tail stderr (live erori)
|
|
5. Open Explorer în folder logs
|
|
6. Șterge toate logs
|
|
|
|
**Rulare:**
|
|
```batch
|
|
view_logs.bat
|
|
```
|
|
|
|
**Use case:** Debugging, monitoring live
|
|
|
|
---
|
|
|
|
## 🔧 Configurare Serviciu Windows
|
|
|
|
### Detalii Serviciu
|
|
|
|
| Proprietate | Valoare |
|
|
|------------|---------|
|
|
| **Service Name** | `BTGOTelegramBot` |
|
|
| **Display Name** | `BTGO Telegram Trigger Bot` |
|
|
| **Executable** | `python.exe` |
|
|
| **Arguments** | `telegram_trigger_bot.py` |
|
|
| **Working Dir** | Project root |
|
|
| **Start Type** | Automatic (Delayed) |
|
|
| **Restart Policy** | On failure, 5s delay |
|
|
| **Stdout Log** | `logs/telegram_bot_stdout.log` |
|
|
| **Stderr Log** | `logs/telegram_bot_stderr.log` |
|
|
| **Log Rotation** | 10 MB max |
|
|
|
|
### Managed by NSSM
|
|
|
|
**NSSM** (Non-Sucking Service Manager) este folosit pentru:
|
|
- ✅ Simplifică crearea serviciilor din Python scripts
|
|
- ✅ Gestionează logging automat
|
|
- ✅ Auto-restart la crash
|
|
- ✅ Gestiune environment variables
|
|
|
|
**Download:** Auto-descărcat de `install_service.bat` în `tools/nssm.exe`
|
|
|
|
**Versiune:** 2.24 (64-bit)
|
|
|
|
---
|
|
|
|
## 📋 Workflow Tipic
|
|
|
|
### Prima Instalare (VM nou)
|
|
|
|
```batch
|
|
# 1. Clone repo
|
|
cd E:\proiecte
|
|
git clone <repo> btgo-playwright
|
|
cd btgo-playwright
|
|
|
|
# 2. Configurează .env
|
|
copy .env.example .env
|
|
notepad .env
|
|
|
|
# 3. Deploy complet
|
|
cd deployment\windows\scripts
|
|
deploy.bat
|
|
|
|
# 4. Verifică status
|
|
status.bat
|
|
|
|
# 5. Test în Telegram
|
|
# Trimite /start la bot
|
|
```
|
|
|
|
---
|
|
|
|
### Update Cod (după modificări)
|
|
|
|
```batch
|
|
# 1. Pull changes
|
|
cd E:\proiecte\btgo-playwright
|
|
git pull
|
|
|
|
# 2. Update requirements (dacă s-au modificat)
|
|
python -m pip install -r requirements.txt
|
|
|
|
# 3. Restart serviciu
|
|
deployment\windows\scripts\restart_service.bat
|
|
|
|
# 4. Verifică logs
|
|
deployment\windows\scripts\view_logs.bat
|
|
```
|
|
|
|
---
|
|
|
|
### Debug Issues
|
|
|
|
```batch
|
|
# 1. Verifică status
|
|
deployment\windows\scripts\status.bat
|
|
|
|
# 2. Verifică logs
|
|
deployment\windows\scripts\view_logs.bat
|
|
# Selectează opțiunea 2 (stderr)
|
|
|
|
# 3. Testează manual (dacă e nevoie)
|
|
net stop BTGOTelegramBot
|
|
python telegram_trigger_bot.py
|
|
# Vezi output direct în terminal
|
|
|
|
# 4. Restart serviciu
|
|
deployment\windows\scripts\restart_service.bat
|
|
```
|
|
|
|
---
|
|
|
|
### Reinstalare Completă
|
|
|
|
```batch
|
|
# 1. Dezinstalează
|
|
deployment\windows\scripts\uninstall_service.bat
|
|
|
|
# 2. Șterge logs vechi (opțional)
|
|
del /q logs\*.log
|
|
|
|
# 3. Reinstalează
|
|
deployment\windows\scripts\deploy.bat
|
|
```
|
|
|
|
---
|
|
|
|
## 🛡️ Securitate
|
|
|
|
**Protecție `.env`:**
|
|
- `.env` este în `.gitignore` (nu se commitează)
|
|
- Conține credențiale sensibile (bot token, parole BTGO)
|
|
- Setează permissions doar pentru Administrator
|
|
|
|
**User IDs Telegram:**
|
|
- `TELEGRAM_ALLOWED_USER_IDS` restricționează accesul
|
|
- Format: `123456789,987654321` (comma-separated)
|
|
- Nu lăsa gol (permite oricui)
|
|
|
|
---
|
|
|
|
## 📞 Support
|
|
|
|
**Documentație:**
|
|
- `README.md` - Documentație completă
|
|
- `QUICK_START.md` - Ghid rapid 5 minute
|
|
- `../../TELEGRAM_BOT_SETUP.md` - Setup Telegram
|
|
- `../../CLAUDE.md` - Documentație proiect
|
|
|
|
**Troubleshooting:**
|
|
1. Verifică `status.bat`
|
|
2. Verifică `view_logs.bat` → stderr
|
|
3. Testează manual: `python telegram_trigger_bot.py`
|
|
|
|
---
|
|
|
|
## 📄 Changelog
|
|
|
|
| Data | Versiune | Modificări |
|
|
|------|----------|-----------|
|
|
| 2025-11-06 | 1.0 | Initial release - Complete deployment suite |
|
|
|
|
---
|
|
|
|
**Happy Deploying! 🚀**
|