From bd14f39105c21ebdaafc9bc630a0f8da14b74a8e Mon Sep 17 00:00:00 2001 From: WebalexEU <28548335+webalexeu@users.noreply.github.com> Date: Mon, 6 Jan 2025 21:55:04 +0100 Subject: [PATCH] Fix process name --- .gitignore | 7 +++++++ CHANGELOG.md | 19 ++++++++++++++++++- builder/build.ps1 | 19 ++++++++++++++++++- builder/main.wxs | 8 ++++---- src/WinBGP-Engine.ps1 | 14 ++++++++++---- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 784f04c..f503ed8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,13 @@ # Service builder executable outputs service/*.exe +# Signed code +engine/*.* + + # Installer outputs builder/*.msi builder/*.wixpdb + +# MSI Release +release/*.msi diff --git a/CHANGELOG.md b/CHANGELOG.md index c769f5e..5ec5dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,24 @@ All notable changes to this project will be documented in this file. +## Release 1.1.2 (2025-01-06) + +[Full Changelog](https://github.com/webalexeu/winbgp/compare/v1.1.1...v1.1.2) + +**Features** + +- Sign API/Engine/HealthCheck/CLI binaries +- Force process to exit when a failure occurs + +**Bugfixes** + +- [API restart cause failure of the engine](https://github.com/webalexeu/winbgp/issues/1) + +**Known Issues** + ## Release 1.1.1 (2024-12-30) -[Full Changelog](https://github.com/webalexeu/winbgp/compare/v1.0.0...v1.1.1) +[Full Changelog](https://github.com/webalexeu/winbgp/compare/v1.1.0...v1.1.1) **Features** @@ -14,6 +29,8 @@ All notable changes to this project will be documented in this file. **Known Issues** +- API restart cause failure of the engine + ## Release 1.1.0 (2024-12-20) diff --git a/builder/build.ps1 b/builder/build.ps1 index e196f81..ec896fd 100644 --- a/builder/build.ps1 +++ b/builder/build.ps1 @@ -4,7 +4,11 @@ Param ( [String] $Version, [Parameter(Mandatory = $false)] [ValidateSet("amd64", "arm64")] - [String] $Arch = "amd64" + [String] $Arch = "amd64", + [Parameter(ParameterSetName='Signing', Mandatory = $false)] + [Switch] $Sign = $false, + [Parameter(ParameterSetName='Signing', Mandatory = $false)] + [String] $CertificateThumbprint ) $ErrorActionPreference = "Stop" @@ -18,6 +22,13 @@ Trap { Pop-Location } +$cert=Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | Where-Object { $_.Thumbprint -eq $CertificateThumbprint } +Get-ChildItem -Path '..\src' | Where-Object {$_.Extension -eq '.ps1'} | ForEach-Object { + Copy-Item -Path $_.FullName -Destination "..\engine" -Force + if ($Sign) { + Set-AuthenticodeSignature -FilePath "..\engine\$($_.Name)" -TimestampServer 'http://time.certum.pl' -Certificate $cert + } +} Write-Verbose "Creating winbgp-${Version}-${Arch}.msi" $wixArch = @{"amd64" = "x64"; "arm64" = "arm64"}[$Arch] @@ -26,3 +37,9 @@ Invoke-Expression "wix build -arch $wixArch -o .\WinBGP-$($Version)-$($Arch).msi Write-Verbose "Done!" Pop-Location + +Copy-Item -Path "WinBGP-$($Version)-$($Arch).msi" -Destination "..\release" -Force +if ($Sign) { + & "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\signtool.exe" sign /sha1 $CertificateThumbprint /tr http://time.certum.pl/ /td sha256 /fd sha256 /v "..\release\WinBGP-$($Version)-$($Arch).msi" +} + diff --git a/builder/main.wxs b/builder/main.wxs index 9115adb..865e4f3 100644 --- a/builder/main.wxs +++ b/builder/main.wxs @@ -167,13 +167,13 @@ - + - + - + @@ -182,7 +182,7 @@ - + diff --git a/src/WinBGP-Engine.ps1 b/src/WinBGP-Engine.ps1 index b46a3e3..038fc3d 100644 --- a/src/WinBGP-Engine.ps1 +++ b/src/WinBGP-Engine.ps1 @@ -66,6 +66,8 @@ $scriptFullName = $argv0.fullname # Ex: C:\Temp\PSService.ps1 # Global settings $serviceName = "WinBGP" # A one-word name used for net start commands $serviceDisplayName = "WinBGP" +# To improve (Service name should be rationalized) +$serviceInternalName = "WinBGP-Service" $ServiceDescription = "The BGP swiss army knife of networking on Windows" $pipeName = "Service_$serviceName" # Named pipe name. Used for sending messages to the service task $installDir = "${ENV:ProgramW6432}\$serviceDisplayName" # Where to install the service files @@ -984,7 +986,7 @@ function Stop-API() { $ProcessID=$null $ApiPID=$null # Get service PID - $ProcessID=(Get-CimInstance Win32_Process -Filter "name = 'powershell.exe'" -OperationTimeoutSec 1 | Where-Object {$_.CommandLine -like "*'$installDir\$serviceDisplayName.ps1' -Service*"}).ProcessId + $ProcessID=(Get-CimInstance Win32_Process -Filter "name = 'powershell.exe'" -OperationTimeoutSec 1 | Where-Object {$_.CommandLine -like "*'$installDir\$serviceInternalName.ps1' -Service*"}).ProcessId if ($ProcessID) { # Get API PID $ApiPID=(Get-WmiObject win32_process -filter "Name='powershell.exe' AND ParentProcessId=$ProcessID").ProcessId @@ -1115,9 +1117,10 @@ if ($Service) { # Run the service $configuration = Get-Content -Path $configdir | ConvertFrom-Json Write-Log "Loading configuration file '$($configdir)'" } else { - Write-Log "Configuration file '$($configdir)' is not valid - Stopping $($serviceDisplayName) process" -Level Error + Write-Log "Configuration file '$($configdir)' is not valid" -Level Warning + Write-Log "Stopping $($serviceInternalName) process" -Level Error # Forcing stop process so service will know that process is not running - Stop-Process -Name $serviceDisplayName -Force + Stop-Process -Name $serviceInternalName -Force exit 1 } @@ -1533,7 +1536,7 @@ if ($Service) { # Run the service } } } else { - Write-Log "Reload aborted - Configuration file '$($configdir)' is not a valid JSON file" -Level Error + Write-Log "Reload aborted - Configuration file '$($configdir)' is not a valid JSON file" -Level Warning } $pipeThread = Start-PipeHandlerThread $pipeName -Event "ControlMessage" } @@ -1728,6 +1731,9 @@ if ($Service) { # Run the service $msg = $_.Exception.Message $line = $_.InvocationInfo.ScriptLineNumber Write-Log -Message "Error at line ${line}: $msg" -Level Error + Write-Log "Stopping $($serviceInternalName) process" -Level Error + # Forcing stop process so service will know that process is not running (to avoid having service running without process) + Stop-Process -Name $serviceInternalName -Force } finally { # Invoked in all cases: Exception or normally by -Stop # Cleanup the periodic timer used in the above example Unregister-Event -SourceIdentifier $timerName