From 4690696fed1b683f12b98dbe6da8a56aa5ccad63 Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Thu, 5 May 2022 18:15:11 +0200 Subject: [PATCH] Hash the Swarm Services too --- bouncer/bouncer | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bouncer/bouncer b/bouncer/bouncer index 0552448..1385382 100755 --- a/bouncer/bouncer +++ b/bouncer/bouncer @@ -345,10 +345,12 @@ class Bouncer private function stateHasChanged(): bool { $newInstanceStates = []; + + // Standard Containers $containers = json_decode($this->client->request('GET', 'containers/json')->getBody()->getContents(), true); foreach ($containers as $container) { $inspect = json_decode($this->client->request('GET', "containers/{$container['Id']}/json")->getBody()->getContents(), true); - $newInstanceStates[$inspect['Id']] = implode('::', [ + $newInstanceStates['container-' . $inspect['Id']] = implode('::', [ $inspect['Name'], $inspect['Created'], $inspect['Image'], @@ -356,6 +358,18 @@ class Bouncer sha1(implode('|', $inspect['Config']['Env'])), ]); } + + // Swarm Services + $services = json_decode($this->client->request('GET', 'services')->getBody()->getContents(), true); + if(isset($services['message'])){ + $this->logger->debug(sprintf('Something happened while interrogating services.. This node is not a swarm node, cannot have services: %s', $services['message'])); + }else{ + foreach($services as $service){ + $newInstanceStates['service-' . $service['ID']] = implode("::", [ + $service['Version']['Index'] + ]); + } + } $newStateHash = sha1(implode("\n", $newInstanceStates)); //$this->logger->debug(sprintf("Old state = %s. New State = %s.", substr($this->instanceStateHash,0,7), substr($newStateHash, 0,7))); if ($this->instanceStateHash != $newStateHash) {