====== Runbook: Servizio Windows ======
**Durata:** ~15 minuti \\
**Ruolo:** Amministratore Windows \\
**Prerequisito:** Diritti Admin, .NET 8 Runtime
Installare e gestire il Data Gateway come servizio Windows.
----
===== Workflow =====
flowchart TD
A[Start] --> B[Copiare Gateway]
B --> C[Registrare servizio]
C --> D[Configurare servizio]
D --> E[Avviare servizio]
E --> F[Health Check]
F --> G{OK?}
G -->|Si| H[Finito]
G -->|No| I[Controllare Event Log]
style H fill:#e8f5e9
style I fill:#ffebee
----
===== 1. Installare Gateway =====
# Creare directory
New-Item -ItemType Directory -Path "%SERVICES_ROOT%\DataGateway" -Force
# Copiare file
Copy-Item -Path ".\publish\*" -Destination "%SERVICES_ROOT%\DataGateway" -Recurse
# Modificare configurazione
notepad "%SERVICES_ROOT%\DataGateway\appsettings.json"
----
===== 2. Creare servizio con sc.exe =====
# Eseguire come Amministratore
sc.exe create "DataGateway" `
binPath= "%SERVICES_ROOT%\DataGateway\WvdS.WebAPI.Data.Gateway.Api.exe" `
DisplayName= "WvdS Data Gateway" `
start= auto `
obj= "NT AUTHORITY\NETWORK SERVICE"
# Impostare descrizione
sc.exe description "DataGateway" "REST/OData/GraphQL API Gateway per database"
----
===== 3. Creare servizio con NSSM (Alternativa) =====
NSSM (Non-Sucking Service Manager) offre piu controllo:
# Scaricare NSSM
Invoke-WebRequest -Uri "https://nssm.cc/release/nssm-2.24.zip" -OutFile "nssm.zip"
Expand-Archive -Path "nssm.zip" -DestinationPath "%TOOLS_PATH%"
# Installare servizio
%TOOLS_PATH%\nssm-2.24\win64\nssm.exe install DataGateway "%SERVICES_ROOT%\DataGateway\WvdS.WebAPI.Data.Gateway.Api.exe"
# Configurazione
nssm set DataGateway AppDirectory "%SERVICES_ROOT%\DataGateway"
nssm set DataGateway DisplayName "WvdS Data Gateway"
nssm set DataGateway Description "REST/OData/GraphQL API Gateway"
nssm set DataGateway Start SERVICE_AUTO_START
nssm set DataGateway AppStdout "%SERVICES_ROOT%\DataGateway\logs\stdout.log"
nssm set DataGateway AppStderr "%SERVICES_ROOT%\DataGateway\logs\stderr.log"
nssm set DataGateway AppRotateFiles 1
nssm set DataGateway AppRotateBytes 10485760
----
===== 4. Avviare servizio =====
# Avviare
Start-Service -Name "DataGateway"
# Controllare stato
Get-Service -Name "DataGateway"
# Fermare
Stop-Service -Name "DataGateway"
# Riavviare
Restart-Service -Name "DataGateway"
----
===== 5. Configurare Autostart =====
# Autostart all'avvio sistema
Set-Service -Name "DataGateway" -StartupType Automatic
# Avvio ritardato (dopo rete)
sc.exe config "DataGateway" start= delayed-auto
# Opzioni Recovery (riavviare in caso di crash)
sc.exe failure "DataGateway" reset= 86400 actions= restart/60000/restart/60000/restart/60000
----
===== 6. Health Check =====
# Attendere che il servizio sia pronto
Start-Sleep -Seconds 5
# Health Check
$response = Invoke-WebRequest -Uri "http://localhost:5000/health" -UseBasicParsing
if ($response.StatusCode -eq 200) {
Write-Host "Gateway funziona!" -ForegroundColor Green
} else {
Write-Host "Problema Gateway!" -ForegroundColor Red
Get-EventLog -LogName Application -Source "DataGateway" -Newest 10
}
----
===== 7. Checklist =====
| # | Punto di verifica | v |
|---|-----------|---|
| 1 | File in %SERVICES_ROOT%\DataGateway | ☐ |
| 2 | appsettings.json configurato | ☐ |
| 3 | Servizio registrato | ☐ |
| 4 | Servizio avviato | ☐ |
| 5 | Health Check riuscito | ☐ |
| 6 | Autostart attivo | ☐ |
| 7 | Recovery configurato | ☐ |
----
===== Troubleshooting =====
| Problema | Causa | Soluzione |
|---------|---------|--------|
| ''Servizio non si avvia'' | .NET Runtime mancante | verificare ''dotnet --info'' |
| ''Access denied'' | Diritti mancanti | Installare come Admin |
| ''Porta gia in uso'' | Altro processo | ''netstat -ano | findstr 5000'' |
| ''Config error'' | Sintassi JSON | validare appsettings.json |
**Controllare Event Log:**
Get-EventLog -LogName Application -Source "DataGateway" -Newest 20 | Format-Table TimeGenerated, EntryType, Message -Wrap
----
===== Rimuovere servizio =====
# Fermare
Stop-Service -Name "DataGateway" -Force
# Rimuovere
sc.exe delete "DataGateway"
# Eliminare file (opzionale)
Remove-Item -Path "%SERVICES_ROOT%\DataGateway" -Recurse -Force
----
===== Runbook Correlati =====
* [[.:docker|Docker]] - Alternativa container
* [[..:tagesgeschaeft:health-check|Health Check]] - Verificare disponibilita
* [[..:sicherheit:tls-einrichten|Configurare TLS]] - Attivare HTTPS
----
<< [[.:start|<- Automazione]] | [[.:systemd|-> systemd]] >>
----
//Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional//
{{tag>operator runbook windows dienst service}}