Skip to content

Commit

Permalink
Fixed possible exception on flushing API dir
Browse files Browse the repository at this point in the history
[#54] Fixed an issue while flushing the API Directory, caused by file
locks of the Agent. New handling will now shut down the Agent, flush the
Directory and start the Agent again afterwards. This will also fix
possible 'false' positives of configuration validation errors
  • Loading branch information
LordHepipud committed Nov 14, 2017
1 parent 3ef03da commit 5b367e9
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Icinga2Agent/Icinga2Agent.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,10 @@ function Icinga2AgentModule {
$installer | Add-Member -membertype ScriptMethod -name 'flushIcingaApiDirectory' -value {
if ((Test-Path $this.getApiDirectory()) -And $this.shouldFlushIcingaApiDirectory()) {
$this.info('Flushing content of ' + $this.getApiDirectory());
$this.stopIcingaService();
[System.Object]$folder = New-Object -ComObject Scripting.FileSystemObject;
$folder.DeleteFolder($this.getApiDirectory());
$this.setProperty('require_restart', 'true');
}
}

Expand Down Expand Up @@ -1247,6 +1249,19 @@ function Icinga2AgentModule {
return $result;
}

#
# Function to stop the Icinga 2 service
#
$installer | Add-Member -membertype ScriptMethod -name 'stopIcingaService' -value {
# Stop the Icinga 2 Service
$this.info('Stopping the Icinga 2 Service...')
$result = $this.startProcess("sc.exe", $TRUE, "stop icinga2");

# Wait until the service is stopped
$serviceResult = $this.waitForServiceToReachState('icinga2', 'Stopped');
$this.info('Icinga 2 service has been stopped.')
}

#
# This function will wait for a specific service until it reaches
# the defined state. Will break after 20 seconds with an error message
Expand Down Expand Up @@ -1776,8 +1791,6 @@ object ApiListener "api" {
$this.backupDefaultConfig();
$this.writeConfig($this.getProperty('new_icinga_config'));

$this.flushIcingaApiDirectory();

# Check if the config is valid and rollback otherwise
if (-Not $this.isIcingaConfigValid()) {
$this.error('Icinga 2 config validation failed. Rolling back to previous version.');
Expand Down Expand Up @@ -2731,6 +2744,11 @@ object ApiListener "api" {
$this.createHostInsideIcingaDirector();
# First check if we should get some parameters from the Icinga Director
$this.fetchTicketFromIcingaDirector();
# Before we continue, flush the API Directory if specified. This will require
# us to stop the Icinga 2 Agent, but should prevent any false positive in
# case dependencies within the API Director are no longer pressent and will
# ensure a possible config rollback is working as intended as well
$this.flushIcingaApiDirectory();

# Try to locate the current
# Installation data from the Agent
Expand Down

0 comments on commit 5b367e9

Please sign in to comment.