Improves Agent installation/uninstallation stability

Fixes #69
This commit is contained in:
Lord Hepipud 2020-05-30 14:42:31 +02:00
parent 7551233f0b
commit 591555f2c1
6 changed files with 48 additions and 13 deletions

View file

@ -31,6 +31,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#67](https://github.com/Icinga/icinga-powershell-framework/issues/67) Adds support to flush entire Icinga 2 ProgamData directory on uninstallation * [#67](https://github.com/Icinga/icinga-powershell-framework/issues/67) Adds support to flush entire Icinga 2 ProgamData directory on uninstallation
* [#68](https://github.com/Icinga/icinga-powershell-framework/issues/68) Improves the setup wizard by providing better understandable prompts including examples and various smaller bugfixes * [#68](https://github.com/Icinga/icinga-powershell-framework/issues/68) Improves the setup wizard by providing better understandable prompts including examples and various smaller bugfixes
* Console prints are now containing a severity message to better keep an eye on possible warnings/errors * Console prints are now containing a severity message to better keep an eye on possible warnings/errors
* [#69](https://github.com/Icinga/icinga-powershell-framework/issues/69) Improves stability of installation/uninstallation of the Agent by using different PowerShell instances for service and installation/uninstallation handling
### Bugfixes ### Bugfixes

View file

@ -24,9 +24,14 @@ function Restart-IcingaService()
$Service $Service
); );
if (Get-Service $Service -ErrorAction SilentlyContinue) { if (Get-Service "$Service" -ErrorAction SilentlyContinue) {
Write-IcingaConsoleNotice ([string]::Format('Restarting service "{0}"', $Service)); Write-IcingaConsoleNotice ([string]::Format('Restarting service "{0}"', $Service));
Restart-Service $Service; powershell.exe -Command {
$Service = $args[0]
Restart-Service "$Service";
} -Args $Service;
} else { } else {
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service; Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
} }

View file

@ -26,7 +26,11 @@ function Start-IcingaService()
if (Get-Service $Service -ErrorAction SilentlyContinue) { if (Get-Service $Service -ErrorAction SilentlyContinue) {
Write-IcingaConsoleNotice -Message 'Starting service "{0}"' -Objects $Service; Write-IcingaConsoleNotice -Message 'Starting service "{0}"' -Objects $Service;
Start-Service $Service; powershell.exe -Command {
$Service = $args[0]
Start-Service "$Service";
} -Args $Service;
} else { } else {
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service; Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
} }

View file

@ -26,7 +26,11 @@ function Stop-IcingaService()
if (Get-Service $Service -ErrorAction SilentlyContinue) { if (Get-Service $Service -ErrorAction SilentlyContinue) {
Write-IcingaConsoleNotice -Message 'Stopping service "{0}"' -Objects $Service; Write-IcingaConsoleNotice -Message 'Stopping service "{0}"' -Objects $Service;
Stop-Service $Service; powershell.exe -Command {
$Service = $args[0]
Stop-Service "$Service";
} -Args $Service;
} else { } else {
Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service; Write-IcingaConsoleWarning -Message 'The service "{0}" is not installed' -Objects $Service;
} }

View file

@ -71,8 +71,16 @@ function Install-IcingaAgent()
} }
} }
$InstallProcess = powershell.exe -Command {
$IcingaInstaller = $args[0];
$InstallTarget = $args[1];
Use-Icinga;
$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;
return $InstallProcess;
} -Args $IcingaInstaller, $InstallTarget;
if ($InstallProcess.ExitCode -ne 0) { if ($InstallProcess.ExitCode -ne 0) {
Write-IcingaConsoleError -Message 'Failed to install Icinga 2 Agent: {0}{1}' -Objects $InstallProcess.Message, $InstallProcess.Error; Write-IcingaConsoleError -Message 'Failed to install Icinga 2 Agent: {0}{1}' -Objects $InstallProcess.Message, $InstallProcess.Error;
return $FALSE; return $FALSE;

View file

@ -5,25 +5,38 @@ function Uninstall-IcingaAgent()
); );
$IcingaData = Get-IcingaAgentInstallation; $IcingaData = Get-IcingaAgentInstallation;
[string]$IcingaProgramData = Join-Path -Path $Env:ProgramData -ChildPath 'icinga2';
if ($IcingaData.Installed -eq $FALSE) { if ($IcingaData.Installed -eq $FALSE) {
Write-IcingaConsoleError 'Unable to uninstall the Icinga Agent. The Agent is not installed'; Write-IcingaConsoleNotice 'Unable to uninstall the Icinga Agent. The Agent is not installed';
return; if ($RemoveDataFolder) {
if (Test-Path $IcingaProgramData) {
Write-IcingaConsoleNotice -Message 'Removing Icinga Agent directory: "{0}"' -Objects $IcingaProgramData;
return ((Remove-ItemSecure -Path $IcingaProgramData -Recurse -Force) -eq $FALSE);
} else {
Write-IcingaConsoleNotice -Message 'Icinga Agent directory "{0}" does not exist' -Objects $IcingaProgramData;
}
}
return $FALSE;
} }
Write-IcingaConsoleNotice 'Removing current Icinga Agent'; $Uninstaller = powershell.exe -Command {
$IcingaData = $args[0]
Use-Icinga;
Stop-IcingaService 'icinga2'; Stop-Service 'icinga2' -ErrorAction SilentlyContinue | Out-Null;
$Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q', $IcingaData.Uninstaller)) -FlushNewLine; $Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q', $IcingaData.Uninstaller)) -FlushNewLine;
return $Uninstaller;
} -Args $IcingaData;
if ($Uninstaller.ExitCode -ne 0) { if ($Uninstaller.ExitCode -ne 0) {
Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error)); Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error));
return $FALSE; return $FALSE;
} }
if ($RemoveDataFolder) { if ($RemoveDataFolder) {
[string]$IcingaProgramData = Join-Path -Path $Env:ProgramData -ChildPath 'icinga2';
Write-IcingaConsoleNotice -Message 'Removing Icinga Agent directory: "{0}"' -Objects $IcingaProgramData; Write-IcingaConsoleNotice -Message 'Removing Icinga Agent directory: "{0}"' -Objects $IcingaProgramData;
if ((Remove-ItemSecure -Path $IcingaProgramData -Recurse -Force) -eq $FALSE) { if ((Remove-ItemSecure -Path $IcingaProgramData -Recurse -Force) -eq $FALSE) {
return $FALSE; return $FALSE;