chore(deployment): add Windows Service publish and install scripts
This commit is contained in:
23
publish-windows-service.ps1
Normal file
23
publish-windows-service.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
# publish-windows-service.ps1
|
||||
# Kullanim: .\publish-windows-service.ps1
|
||||
# Cikti: E:\Publish\MessagingService\WindowsService\
|
||||
|
||||
$project = "$PSScriptRoot\src\presentation\DigitalData.MessagingService.API\DigitalData.MessagingService.API.csproj"
|
||||
$output = "M:\App&Service\0 DD - Funktionsmodule\MessagingService\PreRelease\WindowsService\net8"
|
||||
|
||||
Write-Host "Publishing to $output ..." -ForegroundColor Cyan
|
||||
|
||||
dotnet publish $project `
|
||||
--configuration Release `
|
||||
--runtime win-x64 `
|
||||
--self-contained true `
|
||||
--output $output `
|
||||
-p:EnvironmentName=Production `
|
||||
-p:PublishSingleFile=false
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "Done. Files at: $output" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Publish FAILED." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<PublishDir>M:\App&Service\0 DD - Funktionsmodule\MessagingService\PreRelease\WindowsService\net8\$(AssemblyVersion)\</PublishDir>
|
||||
<PublishDir>E:\Publish\MessagingService\WindowsService\</PublishDir>
|
||||
<DeleteExistingFiles>false</DeleteExistingFiles>
|
||||
<ProjectGuid>5e0e17c0-ff5a-4246-bf87-1add85376a27</ProjectGuid>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
@echo off
|
||||
:: DigitalData MessagingService - Windows Service Installer
|
||||
:: Als Administrator ausfuehren / Run as Administrator
|
||||
::
|
||||
:: Verwendung / Usage:
|
||||
:: install-windows-service.bat
|
||||
::
|
||||
:: Voraussetzung: Dieses Skript liegt im Publish-Verzeichnis neben der .exe
|
||||
|
||||
setlocal
|
||||
|
||||
set SERVICE_NAME=DD-MessagingService
|
||||
set SERVICE_DISPLAY=DigitalData MessagingService
|
||||
set SERVICE_DESC=DigitalData E-Mail Messaging Service - RabbitMQ Consumer + REST API
|
||||
set SERVICE_EXE=%~dp0DigitalData.MessagingService.API.exe
|
||||
set SERVICE_PORT=1415
|
||||
|
||||
echo.
|
||||
echo ============================================================
|
||||
echo DigitalData MessagingService - Windows Service Installation
|
||||
echo ============================================================
|
||||
echo.
|
||||
|
||||
:: Adminrechte pruefen
|
||||
net session >nul 2>&1
|
||||
if %errorlevel% neq 0 (
|
||||
echo [FEHLER] Bitte als Administrator ausfuehren.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: Pruefen ob .exe vorhanden
|
||||
if not exist "%SERVICE_EXE%" (
|
||||
echo [FEHLER] Datei nicht gefunden: %SERVICE_EXE%
|
||||
echo Bitte sicherstellen, dass das Skript im Publish-Verzeichnis liegt.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: Vorhandenen Dienst stoppen und loeschen
|
||||
sc query "%SERVICE_NAME%" >nul 2>&1
|
||||
if %errorlevel% equ 0 (
|
||||
echo [INFO] Vorhandener Dienst wird gestoppt und geloescht...
|
||||
sc stop "%SERVICE_NAME%" >nul 2>&1
|
||||
timeout /t 3 /nobreak >nul
|
||||
sc delete "%SERVICE_NAME%"
|
||||
timeout /t 2 /nobreak >nul
|
||||
)
|
||||
|
||||
:: Dienst erstellen
|
||||
echo [INFO] Dienst wird erstellt...
|
||||
sc create "%SERVICE_NAME%" binPath= "\"%SERVICE_EXE%\"" DisplayName= "%SERVICE_DISPLAY%" start= auto
|
||||
if %errorlevel% neq 0 (
|
||||
echo [FEHLER] Dienst konnte nicht erstellt werden.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: Beschreibung setzen
|
||||
sc description "%SERVICE_NAME%" "%SERVICE_DESC%"
|
||||
|
||||
:: Neustart-Verhalten konfigurieren (bei Absturz automatisch neu starten)
|
||||
sc failure "%SERVICE_NAME%" reset= 86400 actions= restart/5000/restart/10000/restart/30000
|
||||
|
||||
:: Firewall-Regel hinzufuegen
|
||||
echo [INFO] Firewall-Regel wird hinzugefuegt (Port %SERVICE_PORT%)...
|
||||
netsh advfirewall firewall delete rule name="DD MessagingService %SERVICE_PORT%" >nul 2>&1
|
||||
netsh advfirewall firewall add rule name="DD MessagingService %SERVICE_PORT%" dir=in action=allow protocol=TCP localport=%SERVICE_PORT%
|
||||
|
||||
:: Dienst starten
|
||||
echo [INFO] Dienst wird gestartet...
|
||||
sc start "%SERVICE_NAME%"
|
||||
if %errorlevel% neq 0 (
|
||||
echo [WARNUNG] Dienst konnte nicht sofort gestartet werden. Bitte manuell pruefen.
|
||||
) else (
|
||||
echo [OK] Dienst gestartet.
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ============================================================
|
||||
echo Installation abgeschlossen.
|
||||
echo API erreichbar unter: http://localhost:%SERVICE_PORT%/swagger
|
||||
echo Logs: %~dp0logs\
|
||||
echo ============================================================
|
||||
echo.
|
||||
pause
|
||||
Reference in New Issue
Block a user