mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Adds support to restore original config after using old PS module
Fixes #65
This commit is contained in:
parent
96733eb791
commit
c0e006640a
2 changed files with 31 additions and 0 deletions
30
lib/core/icingaagent/misc/Reset-IcingaAgentConfigFile.psm1
Normal file
30
lib/core/icingaagent/misc/Reset-IcingaAgentConfigFile.psm1
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Checks for old configurations provided by the old PowerShell module
|
||||||
|
and restores the original configuration file
|
||||||
|
.DESCRIPTION
|
||||||
|
Restores the original Icinga 2 configuration by replacing the existing
|
||||||
|
configuration created by the old PowerShell module with the plain one
|
||||||
|
from the Icinga 2 backup file
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Restores original Icinga 2 configuration icinga2.conf
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Reset-IcingaAgentConfigFile;
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Reset-IcingaAgentConfigFile()
|
||||||
|
{
|
||||||
|
$ConfigDir = Get-IcingaAgentConfigDirectory;
|
||||||
|
$OldConfig = Join-Path -Path $ConfigDir -ChildPath 'icinga2.conf';
|
||||||
|
$OldConfigBackup = Join-Path -Path $ConfigDir -ChildPath 'icinga2.conf.old.module';
|
||||||
|
$OriginalConfig = Join-Path -Path $ConfigDir -ChildPath 'icinga2.confdirector.bak';
|
||||||
|
|
||||||
|
if ((Test-Path $OriginalConfig)) {
|
||||||
|
Write-Host 'Found icinga2.conf backup file created by old PowerShell module. Restoring original configuration';
|
||||||
|
|
||||||
|
Move-Item -Path $OldConfig -Destination $OldConfigBackup;
|
||||||
|
Move-Item -Path $OriginalConfig -Destination $OldConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -474,6 +474,7 @@ function Start-IcingaAgentInstallWizard()
|
||||||
|
|
||||||
if ($RunInstaller) {
|
if ($RunInstaller) {
|
||||||
if ((Install-IcingaAgent -Version $AgentVersion -Source $PackageSource -AllowUpdates $AllowVersionChanges) -Or $Reconfigure) {
|
if ((Install-IcingaAgent -Version $AgentVersion -Source $PackageSource -AllowUpdates $AllowVersionChanges) -Or $Reconfigure) {
|
||||||
|
Reset-IcingaAgentConfigFile;
|
||||||
Move-IcingaAgentDefaultConfig;
|
Move-IcingaAgentDefaultConfig;
|
||||||
Set-IcingaAgentNodeName -Hostname $Hostname;
|
Set-IcingaAgentNodeName -Hostname $Hostname;
|
||||||
Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null;
|
Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue