Files
Data-Coupler/WINDOWS_SERVICE_DEPLOYMENT.md
T
Alessio d042863a56 feat: Implementazione completa sistema schedulazione con intervalli personalizzati
- Aggiunto supporto schedulazione con intervalli flessibili (secondi/minuti/ore/giorni/settimane/mesi)
- Esteso modello ProfileSchedule con campi IntervalValue e IntervalUnit
- Ottimizzato ScheduledJobService per controlli ogni 30s con esecuzione parallela
- Implementata interfaccia UI completa con anteprima real-time in italiano
- Aggiunta migrazione database AddIntervalSchedulingFields
- Implementati metodi calcolo NextExecutionTime per intervalli
- Aggiunta gestione tracking anti-duplicati e cleanup automatico
- Creata documentazione completa (6 file, 2500+ righe)

Modifiche tecniche:
- ProfileSchedule.cs: Nuovi campi e metodi CalculateNextInterval/GetScheduleDescription
- ScheduledJobService.cs: Ridotto check interval a 30s, aggiunto parallel processing
- ProfileScheduleService.cs: Supporto calcolo intervalli in UpdateNextExecutionTimeAsync
- Scheduling.razor: Aggiunta sezione UI per configurazione intervalli
- Scheduling.razor.cs: Implementato GetIntervalPreview() e gestione stato campi
2025-10-02 01:12:39 +02:00

207 lines
5.8 KiB
Markdown

# 🚀 Guida Deploy Windows Service - Data Coupler
## 📋 Problemi Risolti
### ❌ **Problemi Identificati**
1. **Timeout Windows Service**: Inizializzazione database troppo lenta
2. **Background Services Duplicati**: Conflitti tra `ScheduledJobService` e `ScheduledExecutionBackgroundService`
3. **Percorso Database**: Problemi di permessi per servizi Windows
4. **Logging Insufficiente**: Mancanza di log per troubleshooting
5. **Configurazione Timeout**: Timeout predefiniti troppo bassi
### ✅ **Soluzioni Implementate**
#### 1. **Configurazione Windows Service Ottimizzata**
- Aggiunto `UseWindowsService()` con configurazione esplicita
- Configurato Event Log per logging centralizzato
- Ottimizzati timeout Kestrel per servizi Windows
#### 2. **Inizializzazione Database Asincrona**
- Timeout di 60 secondi per inizializzazione database
- Retry logic e fallback graceful
- Logging dettagliato per troubleshooting
#### 3. **Gestione Percorsi Sicura**
- Database in `C:\ProgramData\Data_Coupler\` con permessi corretti
- Creazione automatica directory con permessi NETWORK SERVICE
- Fallback paths per compatibilità
#### 4. **Background Service Ottimizzato**
- Rimosso servizio duplicato (`ScheduledExecutionBackgroundService`)
- Delay iniziale di 10 secondi per permettere inizializzazione completa
- Error handling migliorato con retry intelligente
## 🛠️ **Istruzioni Deploy**
### **Metodo 1: Script Automatico (Raccomandato)**
```powershell
# 1. Naviga alla directory del progetto
cd "C:\Users\DalSantoA\OneDrive\Progetti\Altro\Data-Coupler"
# 2. Esegui il build e deploy automatico
.\Scripts\build-and-deploy.ps1 -InstallService -CleanBuild
# 3. Il servizio sarà installato e avviato automaticamente
```
### **Metodo 2: Manuale**
```powershell
# 1. Build e Publish
dotnet publish Data_Coupler\Data_Coupler.csproj `
-c Release `
-o "C:\Services\DataCoupler" `
--self-contained true `
--runtime win-x64 `
-p:PublishReadyToRun=true
# 2. Installa il servizio (come Amministratore)
.\Scripts\install-service.ps1 -ServicePath "C:\Services\DataCoupler\Data_Coupler.exe"
```
### **Metodo 3: Deploy Personalizzato**
```powershell
# Build in directory specifica
dotnet publish Data_Coupler\Data_Coupler.csproj `
-c Release `
-o "C:\Temp\Publish\Data_Coupler" `
--self-contained true `
--runtime win-x64
# Copia file nella directory del servizio
Copy-Item -Path "C:\Temp\Publish\Data_Coupler\*" -Destination "C:\Services\DataCoupler" -Recurse -Force
# Installa servizio manualmente
New-Service -Name "DataCouplerService" `
-BinaryPathName "C:\Services\DataCoupler\Data_Coupler.exe" `
-DisplayName "Data Coupler Service" `
-Description "Servizio per l'integrazione e trasferimento dati multi-platform" `
-StartupType Automatic
```
## 🔧 **Configurazioni Chiave**
### **appsettings.Production.json**
```json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Data_Coupler.BackgroundServices": "Information"
},
"EventLog": {
"LogLevel": {
"Data_Coupler": "Information"
}
}
},
"Kestrel": {
"Limits": {
"KeepAliveTimeout": "00:10:00",
"RequestHeadersTimeout": "00:05:00"
}
}
}
```
### **Percorsi File**
- **Eseguibile**: `C:\Services\DataCoupler\Data_Coupler.exe`
- **Database**: `C:\ProgramData\Data_Coupler\credentials.db`
- **Log**: Event Viewer → Windows Logs → Application → Source: "DataCouplerService"
## 🔍 **Troubleshooting**
### **1. Servizio non si avvia (Timeout)**
```powershell
# Controlla i log
Get-EventLog -LogName Application -Source "DataCouplerService" -Newest 10
# Verifica permessi database
icacls "C:\ProgramData\Data_Coupler"
# Test avvio manuale
cd "C:\Services\DataCoupler"
.\Data_Coupler.exe
```
### **2. Errori Database**
```powershell
# Verifica esistenza directory
Test-Path "C:\ProgramData\Data_Coupler"
# Crea directory manualmente
New-Item -ItemType Directory -Path "C:\ProgramData\Data_Coupler" -Force
# Imposta permessi
$acl = Get-Acl "C:\ProgramData\Data_Coupler"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("NETWORK SERVICE", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($accessRule)
Set-Acl "C:\ProgramData\Data_Coupler" $acl
```
### **3. Porta in Uso**
```powershell
# Verifica porta 7550
netstat -ano | findstr :7550
# Cambia porta in appsettings.json
"Urls": "http://*:7551"
```
### **4. Riavvio Servizio**
```powershell
# Riavvia servizio
Restart-Service -Name "DataCouplerService"
# Controlla stato
Get-Service -Name "DataCouplerService"
```
## 📊 **Monitoraggio**
### **Comandi Utili**
```powershell
# Stato servizio
Get-Service -Name "DataCouplerService"
# Log recenti
Get-EventLog -LogName Application -Source "DataCouplerService" -Newest 10
# Performance
Get-Process -Name "Data_Coupler" | Select-Object ProcessName, CPU, WorkingSet
# Verifica connessione
Test-NetConnection -ComputerName localhost -Port 7550
```
### **Log Locations**
- **Windows Event Log**: Application → DataCouplerService
- **Console Output**: Per debug avvio manuale
- **Application Logs**: Directory servizio (se configurato)
## 🎯 **Risultati Attesi**
Dopo il deploy corretto:
- ✅ Servizio si avvia entro 30 secondi
- ✅ Database inizializzato automaticamente
- ✅ Background services attivi senza conflitti
- ✅ Applicazione accessibile su http://localhost:7550
- ✅ Log visibili in Event Viewer
## 🔄 **Disinstallazione**
```powershell
# Script automatico
.\Scripts\uninstall-service.ps1
# Manuale
Stop-Service -Name "DataCouplerService"
sc.exe delete "DataCouplerService"
Remove-Item -Path "C:\Services\DataCoupler" -Recurse -Force
```
---
**Nota**: Tutti gli script devono essere eseguiti come **Amministratore** per gestire servizi Windows e permessi file system.