Skip to content

Commit 5ae390f

Browse files
authored
Merge pull request #365 from Icinga:fix/ignore_agent_config_on_install_failure
Fix: Icinga environment corruption on Icinga Agent installation failure In case the Icinga Agent could not be installed, regardless of the reason, we should not write any zone, api or other related config to the environment. By doing so, we can corrupt the environment and make it impossible for the Icinga Agent to be installed in the future, unless we manually delete the folowing directories: * `C:\ProgramData\icinga2` * `C:\Program Files\ICINGA2` * `C:\Program Files (x86)\ICINGA2` (only for x86 installations)
2 parents 7b6b9e8 + 8492a39 commit 5ae390f

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1616
* [#361](https://github.com/Icinga/icinga-powershell-framework/issues/361) Fixes IMC freeze on Icinga Director Self-Service installation, in case no Agent installation set on Self-Service API config
1717
* [#362](https://github.com/Icinga/icinga-powershell-framework/issues/362) Fixes repository component installation from file share locations
1818
* [#363](https://github.com/Icinga/icinga-powershell-framework/issues/363) Fixes unneeded continue for JEA process lookup, in case no JEA pid is present
19+
* [#365](https://github.com/Icinga/icinga-powershell-framework/issues/365) Fixes Icinga environment corruption on Icinga Agent installation failure
1920

2021
### Enhancements
2122

lib/core/installer/Start-IcingaForWindowsInstallation.psm1

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,35 @@ function Start-IcingaForWindowsInstallation()
165165
if ($InstallAgent) {
166166
Set-IcingaPowerShellConfig -Path 'Framework.Icinga.AgentLocation' -Value $AgentInstallDir;
167167
Install-IcingaComponent -Name 'agent' -Version $AgentVersion -Confirm -Release;
168-
Reset-IcingaAgentConfigFile;
169-
Move-IcingaAgentDefaultConfig;
170-
Set-IcingaAgentNodeName -Hostname $Hostname;
171-
Set-IcingaAgentServiceUser -User $ServiceUser -Password (ConvertTo-IcingaSecureString $ServicePassword) -SetPermission | Out-Null;
172-
Install-IcingaAgentBaseFeatures;
173-
Write-IcingaAgentApiConfig -Port $IcingaPort;
174-
}
175168

176-
if ((Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $IcingaCAServer -Port $IcingaPort -CACert $CertificateCAFile -Ticket $CertificateTicket) -eq $FALSE) {
177-
Disable-IcingaAgentFeature 'api';
178-
Write-IcingaConsoleWarning `
179-
-Message '{0}{1}{2}{3}{4}' `
180-
-Objects (
181-
'Your Icinga Agent API feature has been disabled. Please provide either your ca.crt ',
182-
'or connect to a parent node for certificate requests. You can run "Install-IcingaAgentCertificates" ',
183-
'with your configuration to properly create the host certificate and a valid certificate request. ',
184-
'After this you can enable the API feature by using "Enable-IcingaAgentFeature api" and restart the ',
185-
'Icinga Agent service "Restart-IcingaService icinga2"'
186-
);
169+
# Only continue this, if our installation was successful
170+
if ((Get-IcingaAgentInstallation).Installed) {
171+
Reset-IcingaAgentConfigFile;
172+
Move-IcingaAgentDefaultConfig;
173+
Set-IcingaAgentNodeName -Hostname $Hostname;
174+
Set-IcingaAgentServiceUser -User $ServiceUser -Password (ConvertTo-IcingaSecureString $ServicePassword) -SetPermission | Out-Null;
175+
Install-IcingaAgentBaseFeatures;
176+
Write-IcingaAgentApiConfig -Port $IcingaPort;
177+
}
187178
}
188179

189-
Write-IcingaAgentZonesConfig -Endpoints $IcingaEndpoints -EndpointConnections $IcingaParentAddresses -ParentZone $IcingaZone -GlobalZones $GlobalZones -Hostname $Hostname;
180+
# Only continue this, if our installation was successful
181+
if ((Get-IcingaAgentInstallation).Installed) {
182+
if ((Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $IcingaCAServer -Port $IcingaPort -CACert $CertificateCAFile -Ticket $CertificateTicket) -eq $FALSE) {
183+
Disable-IcingaAgentFeature 'api';
184+
Write-IcingaConsoleWarning `
185+
-Message '{0}{1}{2}{3}{4}' `
186+
-Objects (
187+
'Your Icinga Agent API feature has been disabled. Please provide either your ca.crt ',
188+
'or connect to a parent node for certificate requests. You can run "Install-IcingaAgentCertificates" ',
189+
'with your configuration to properly create the host certificate and a valid certificate request. ',
190+
'After this you can enable the API feature by using "Enable-IcingaAgentFeature api" and restart the ',
191+
'Icinga Agent service "Restart-IcingaService icinga2"'
192+
);
193+
}
194+
195+
Write-IcingaAgentZonesConfig -Endpoints $IcingaEndpoints -EndpointConnections $IcingaParentAddresses -ParentZone $IcingaZone -GlobalZones $GlobalZones -Hostname $Hostname;
196+
}
190197

191198
if ($InstallService) {
192199
Set-IcingaPowerShellConfig -Path 'Framework.Icinga.IcingaForWindowsService' -Value $WindowsServiceDir;

0 commit comments

Comments
 (0)