Durata: ~10 minuti
Ruolo: Amministratore Linux
Prerequisito: root/sudo, .NET 8 Runtime
Eseguire Data Gateway come servizio systemd su Linux.
# Creare directory sudo mkdir -p /opt/data-gateway sudo chown $USER:$USER /opt/data-gateway # Copiare file cp -r ./publish/* /opt/data-gateway/ # Rendere eseguibile chmod +x /opt/data-gateway/WvdS.WebAPI.Data.Gateway.Api # Modificare configurazione sudo nano /opt/data-gateway/appsettings.json
# Utente dedicato per il servizio sudo useradd --system --no-create-home --shell /sbin/nologin datagateway # Impostare permessi sudo chown -R datagateway:datagateway /opt/data-gateway
sudo nano /etc/systemd/system/data-gateway.service
Contenuto:
[Unit] Description=WvdS Data Gateway Documentation=https://wiki.example.com/data-gateway After=network.target [Service] Type=notify User=datagateway Group=datagateway WorkingDirectory=/opt/data-gateway ExecStart=/opt/data-gateway/WvdS.WebAPI.Data.Gateway.Api Restart=always RestartSec=10 KillSignal=SIGINT SyslogIdentifier=data-gateway Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false # Sicurezza NoNewPrivileges=true ProtectSystem=strict ProtectHome=true PrivateTmp=true ReadWritePaths=/opt/data-gateway/logs ReadWritePaths=/opt/data-gateway/data # Limiti LimitNOFILE=65536 TimeoutStopSec=30 [Install] WantedBy=multi-user.target
# Ricaricare systemd sudo systemctl daemon-reload # Attivare autostart sudo systemctl enable data-gateway # Avviare servizio sudo systemctl start data-gateway # Controllare stato sudo systemctl status data-gateway
# Attendere che sia pronto sleep 5 # Health Check curl -s http://localhost:5000/health # Risposta attesa: "Healthy" # Test API curl -s http://localhost:5000/api/v1/dsn/demo/tables | head
# Log attuali sudo journalctl -u data-gateway -n 50 --no-pager # Live-Tail sudo journalctl -u data-gateway -f # Da oggi sudo journalctl -u data-gateway --since today # Solo errori sudo journalctl -u data-gateway -p err
| # | Punto di verifica | v |
| — | ———– | — |
| 1 | .NET 8 installato | ☐ |
| 2 | Gateway in /opt/data-gateway | ☐ |
| 3 | Service-User creato | ☐ |
| 4 | Unit-file creato | ☐ |
| 5 | Servizio enabled | ☐ |
| 6 | Servizio avviato | ☐ |
| 7 | Health Check OK | ☐ |
| Comando | Descrizione |
| ——– | ————– |
systemctl start data-gateway | Avviare |
systemctl stop data-gateway | Fermare |
systemctl restart data-gateway | Riavviare |
systemctl status data-gateway | Stato |
systemctl enable data-gateway | Autostart on |
systemctl disable data-gateway | Autostart off |
| Problema | Causa | Soluzione |
| ——— | ——— | ——– |
code=exited, status=203 | Percorso sbagliato | verificare ExecStart |
code=exited, status=1 | Errore config | controllare journalctl |
Permission denied | Permessi errati | controllare chown |
Address already in use | Porta occupata | altra porta o killare processo |
Analisi errori dettagliata:
# Testare eseguibile direttamente sudo -u datagateway /opt/data-gateway/WvdS.WebAPI.Data.Gateway.Api # Problemi SELinux (RHEL/CentOS) sudo ausearch -m avc -ts recent sudo setsebool -P httpd_can_network_connect 1
In appsettings.json:
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:8080"
}
}
}
}
Aprire firewall:
# firewalld (RHEL/CentOS) sudo firewall-cmd --permanent --add-port=8080/tcp sudo firewall-cmd --reload # ufw (Ubuntu/Debian) sudo ufw allow 8080/tcp
# Fermare e disattivare sudo systemctl stop data-gateway sudo systemctl disable data-gateway # Rimuovere file unit sudo rm /etc/systemd/system/data-gateway.service sudo systemctl daemon-reload # Rimuovere file (opzionale) sudo rm -rf /opt/data-gateway sudo userdel datagateway
« <- Servizio Windows | -> Docker »
Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional