autoconf - fix wait and redis

This commit is contained in:
bunkerity
2021-08-02 16:37:50 +02:00
parent 5a26d06c87
commit 021147f9d9
12 changed files with 66 additions and 36 deletions

View File

@@ -137,6 +137,7 @@ class Config :
if self.__lock :
self.__lock.acquire()
ret = True
nb = 0
urls = []
if self.__type == Controller.Type.SWARM :
for instance in instances :
@@ -158,9 +159,10 @@ class Config :
pass
if req and req.status_code == 200 and req.text == "ok" :
log("config", "INFO", "successfully sent API order to " + url)
nb += 1
else :
log("config", "INFO", "failed API order to " + url)
ret = False
if self.__lock :
self.__lock.release()
return ret
return ret and nb > 0

View File

@@ -1,4 +1,4 @@
import docker
import docker, time
import Controller
from logger import log
@@ -58,5 +58,14 @@ class DockerController(Controller.Controller) :
def wait(self) :
# TODO : healthcheck ?
return True
# Wait for a container
instances = self.__get_instances()
while len(instances) == 0 :
time.sleep(1)
instances = self.__get_instances()
# Generate first config
env = self.get_env()
if not self.gen_conf(env) :
return False, env
# Wait for nginx
return self._config.wait(instances), env

View File

@@ -1,4 +1,4 @@
import docker
import docker, time
from threading import Lock
from logger import log
@@ -59,4 +59,14 @@ class SwarmController(Controller.Controller) :
return self._reload(self.__get_instances())
def wait(self) :
return self._config.wait(self.__get_instances())
# Wait for a service
instances = self.__get_instances()
while len(instances) == 0 :
time.sleep(1)
instances = self.__get_instances()
# Generate first config
env = self.get_env()
if not self.gen_conf(env) :
return False, env
# Wait for nginx
return self._config.wait(instances), env

View File

@@ -32,21 +32,14 @@ if swarm or kubernetes :
log("autoconf", "INFO", "start reload server in background")
(server, thread) = run_reload_server(controller)
# Apply the first config for existing services
current_env = controller.get_env()
if current_env != {} :
log("autoconf", "INFO", "generating the initial configuration...")
if controller.gen_conf(current_env) :
log("autoconf", "INFO", "initial configuration successfully generated")
else :
log("autoconf", "ERROR", "error while generating initial configuration")
# Wait for instances
if controller.wait() :
log("autoconf", "INFO", "wait until a bunkerized-nginx instance is started ...")
ret, env = controller.wait()
if ret :
log("autoconf", "INFO", "bunkerized-nginx instances started")
else :
log("autoconf", "ERROR", "bunkerized-nginx instances not started")
# Process events
log("autoconf", "INFO", "waiting for events ...")
controller.process_events(current_env)
controller.process_events(env)