mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Fixes possible service lock and error handling
This commit is contained in:
parent
43252ced15
commit
733f3cfe3b
11 changed files with 75 additions and 41 deletions
|
|
@ -16,6 +16,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
* [#472](https://github.com/Icinga/icinga-powershell-framework/pull/472) Fixes random errors while dynamically compiling Add-Type code by now writing a DLL inside `cache/dll` for later usage
|
||||
* [#472](https://github.com/Icinga/icinga-powershell-framework/pull/472) Fixes random errors while dynamically compiling Add-Type code by now writing a DLL inside `cache/dll` for later usage
|
||||
* [#479](https://github.com/Icinga/icinga-powershell-framework/pull/479) Fixes possible exceptions while trying to remove downloaded repository temp files which might still contain a file lock from virusscanners or other tasks
|
||||
* [#480](https://github.com/Icinga/icinga-powershell-framework/pull/480) Fixes service locking during Icinga Agent upgrade and ensures errors on service management are caught and printed with internal error handling
|
||||
|
||||
### Enhancements
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ function Install-IcingaFrameworkComponent()
|
|||
|
||||
if ([string]::IsNullOrEmpty((Get-IcingaJEAContext)) -eq $FALSE) {
|
||||
Write-IcingaConsoleNotice 'Updating Icinga JEA profile';
|
||||
Invoke-IcingaCommand { Install-IcingaJEAProfile };
|
||||
Invoke-IcingaCommand { Install-IcingaJEAProfile; };
|
||||
}
|
||||
|
||||
# Unload the module if it was loaded before
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ function Install-IcingaFrameworkUpdate()
|
|||
if ([string]::IsNullOrEmpty((Get-IcingaJEAContext)) -eq $FALSE) {
|
||||
Remove-IcingaFrameworkDependencyFile;
|
||||
Write-IcingaConsoleNotice 'Updating Icinga JEA profile';
|
||||
Invoke-IcingaCommand { Install-IcingaJEAProfile };
|
||||
Invoke-IcingaCommand { Install-IcingaJEAProfile; };
|
||||
}
|
||||
|
||||
Write-IcingaConsoleNotice 'Framework update has been completed. Please start a new PowerShell instance now to complete the update';
|
||||
|
|
|
|||
|
|
@ -20,18 +20,25 @@
|
|||
|
||||
function Restart-IcingaService()
|
||||
{
|
||||
param(
|
||||
param (
|
||||
$Service
|
||||
);
|
||||
|
||||
if (Get-Service "$Service" -ErrorAction SilentlyContinue) {
|
||||
Write-IcingaConsoleNotice ([string]::Format('Restarting service "{0}"', $Service));
|
||||
powershell.exe -Command {
|
||||
$Service = $args[0]
|
||||
|
||||
Restart-Service "$Service";
|
||||
} -Args $Service;
|
||||
Invoke-IcingaCommand -ArgumentList $Service -ScriptBlock {
|
||||
try {
|
||||
Restart-Service "$($IcingaShellArgs[0])" -ErrorAction Stop;
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
} catch {
|
||||
Write-IcingaConsoleError -Message 'Failed to restart service "{0}". Error: {1}' -Objects $IcingaShellArgs[0], $_.Exception.Message;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
|
||||
}
|
||||
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,19 @@ function Start-IcingaService()
|
|||
|
||||
if (Get-Service $Service -ErrorAction SilentlyContinue) {
|
||||
Write-IcingaConsoleNotice -Message 'Starting service "{0}"' -Objects $Service;
|
||||
powershell.exe -Command {
|
||||
$Service = $args[0]
|
||||
|
||||
Start-Service "$Service";
|
||||
} -Args $Service;
|
||||
Invoke-IcingaCommand -ArgumentList $Service -ScriptBlock {
|
||||
try {
|
||||
Start-Service "$($IcingaShellArgs[0])" -ErrorAction Stop;
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
} catch {
|
||||
Write-IcingaConsoleError -Message 'Failed to start service "{0}". Error: {1}' -Objects $IcingaShellArgs[0], $_.Exception.Message;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
|
||||
}
|
||||
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,19 @@ function Stop-IcingaService()
|
|||
|
||||
if (Get-Service $Service -ErrorAction SilentlyContinue) {
|
||||
Write-IcingaConsoleNotice -Message 'Stopping service "{0}"' -Objects $Service;
|
||||
powershell.exe -Command {
|
||||
$Service = $args[0]
|
||||
|
||||
Stop-Service "$Service";
|
||||
} -Args $Service;
|
||||
Invoke-IcingaCommand -ArgumentList $Service -ScriptBlock {
|
||||
try {
|
||||
Stop-Service "$($IcingaShellArgs[0])" -ErrorAction Stop;
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
} catch {
|
||||
Write-IcingaConsoleError -Message 'Failed to stop service "{0}". Error: {1}' -Objects $IcingaShellArgs[0], $_.Exception.Message;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
|
||||
}
|
||||
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,15 +73,17 @@ function Install-IcingaAgent()
|
|||
}
|
||||
}
|
||||
|
||||
$InstallProcess = powershell.exe -Command {
|
||||
$IcingaInstaller = $args[0];
|
||||
$InstallTarget = $args[1];
|
||||
Use-Icinga;
|
||||
$InstallProcess = Invoke-IcingaCommand -ArgumentList $IcingaInstaller, $InstallTarget -ScriptBlock {
|
||||
$IcingaInstaller = $IcingaShellArgs[0];
|
||||
$InstallTarget = $IcingaShellArgs[1];
|
||||
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $IcingaInstaller.InstallerPath, $InstallTarget)) -FlushNewLines;
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $IcingaInstaller.InstallerPath, $InstallTarget)) -FlushNewLines;
|
||||
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
|
||||
return $InstallProcess;
|
||||
} -Args $IcingaInstaller, $InstallTarget;
|
||||
}
|
||||
|
||||
if ($InstallProcess.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to install Icinga 2 Agent: {0}{1}' -Objects $InstallProcess.Message, $InstallProcess.Error;
|
||||
|
|
|
|||
|
|
@ -20,16 +20,18 @@ function Uninstall-IcingaAgent()
|
|||
return $FALSE;
|
||||
}
|
||||
|
||||
$Uninstaller = powershell.exe -Command {
|
||||
$IcingaData = $args[0]
|
||||
Use-Icinga;
|
||||
Stop-IcingaService -Service 'icinga2';
|
||||
|
||||
Stop-Service 'icinga2' -ErrorAction SilentlyContinue | Out-Null;
|
||||
$Uninstaller = Invoke-IcingaCommand -ArgumentList $IcingaData -ScriptBlock {
|
||||
$IcingaData = $IcingaShellArgs[0];
|
||||
|
||||
$Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q', $IcingaData.Uninstaller)) -FlushNewLine;
|
||||
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
|
||||
return $Uninstaller;
|
||||
} -Args $IcingaData;
|
||||
}
|
||||
|
||||
if ($Uninstaller.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error));
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'DisabledReason' = 'The Icinga Agent service is either not installed or the service is already running';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Start-Service';
|
||||
'Arguments' = @{ '-Name' = 'icinga2'; };
|
||||
'Command' = 'Start-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
|
|
@ -36,8 +36,8 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'DisabledReason' = 'The Icinga Agent service is either not installed or the service is not running';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Stop-Service';
|
||||
'Arguments' = @{ '-Name' = 'icinga2'; };
|
||||
'Command' = 'Stop-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
|
|
@ -48,8 +48,8 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'DisabledReason' = 'The Icinga Agent service is not installed';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Restart-Service';
|
||||
'Arguments' = @{ '-Name' = 'icinga2'; };
|
||||
'Command' = 'Restart-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icinga2'; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
|
|
@ -71,8 +71,8 @@ function Show-IcingaForWindowsMenuManageIcingaForWindowsServices()
|
|||
'DisabledReason' = 'The Icinga for Windows service is either not installed or already running';
|
||||
'AdminMenu' = $TRUE;
|
||||
'Action' = @{
|
||||
'Command' = 'Start-Service';
|
||||
'Arguments' = @{ '-Name' = 'icingapowershell'; };
|
||||
'Command' = 'Start-IcingaService';
|
||||
'Arguments' = @{ '-Service' = 'icingapowershell'; };
|
||||
}
|
||||
},
|
||||
@{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ function Test-IcingaJEAServiceRunning()
|
|||
return $FALSE;
|
||||
}
|
||||
|
||||
if ($JeaPid -eq '0' -Or $JeaPid -eq 0) {
|
||||
return $FALSE;
|
||||
}
|
||||
|
||||
$JeaPowerShellProcess = Get-Process -Id $JeaPid -ErrorAction SilentlyContinue;
|
||||
if ($null -eq $JeaPowerShellProcess) {
|
||||
return $FALSE;
|
||||
|
|
|
|||
|
|
@ -348,7 +348,9 @@ function Install-IcingaComponent()
|
|||
}
|
||||
}
|
||||
|
||||
$MSIData = & powershell.exe -Command { Use-Icinga; return Read-IcingaMSIMetadata -File $args[0] } -Args $DownloadDestination;
|
||||
$MSIData = Invoke-IcingaCommand -ArgumentList $DownloadDestination -ScriptBlock {
|
||||
return (Read-IcingaMSIMetadata -File $IcingaShellArgs[0]);
|
||||
}
|
||||
|
||||
if ($InstalledVersion.Full -eq $MSIData.ProductVersion -And $Force -eq $FALSE) {
|
||||
Write-IcingaConsoleWarning 'The package "agent" with version "{0}" is already installed. Use "-Force" to re-install the component' -Objects $InstalledVersion.Full;
|
||||
|
|
@ -365,15 +367,17 @@ function Install-IcingaComponent()
|
|||
}
|
||||
}
|
||||
|
||||
$InstallProcess = powershell.exe -Command {
|
||||
$IcingaInstaller = $args[0];
|
||||
$InstallTarget = $args[1];
|
||||
Use-Icinga;
|
||||
$InstallProcess = Invoke-IcingaCommand -ArgumentList $DownloadDestination, $InstallTarget -ScriptBlock {
|
||||
$IcingaInstaller = $IcingaShellArgs[0];
|
||||
$InstallTarget = $IcingaShellArgs[1];
|
||||
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $IcingaInstaller, $InstallTarget)) -FlushNewLines;
|
||||
$InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $IcingaInstaller, $InstallTarget)) -FlushNewLines;
|
||||
|
||||
Start-Sleep -Seconds 2;
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
|
||||
return $InstallProcess;
|
||||
} -Args $DownloadDestination, $InstallTarget;
|
||||
}
|
||||
|
||||
if ($InstallProcess.ExitCode -ne 0) {
|
||||
Write-IcingaConsoleError -Message 'Failed to install component "agent": {0}{1}' -Objects $InstallProcess.Message, $InstallProcess.Error;
|
||||
|
|
|
|||
Loading…
Reference in a new issue