autoconf - prevent race condition by checking health state
This commit is contained in:
parent
3bd3b6fd7a
commit
ad52ef3260
@ -10,6 +10,9 @@
|
|||||||
- Display the reason when generator is ignoring a variable
|
- Display the reason when generator is ignoring a variable
|
||||||
- Various bug fixes related to certbot and jobs
|
- Various bug fixes related to certbot and jobs
|
||||||
- Split jobs into pre and post jobs
|
- Split jobs into pre and post jobs
|
||||||
|
- Fix race condition when using autoconf without Swarm by checking healthy state
|
||||||
|
- Add HEALTHCHECK to image
|
||||||
|
- Bump modsecurity-nginx to v1.0.2
|
||||||
|
|
||||||
## v1.2.6 - 2021/06/06
|
## v1.2.6 - 2021/06/06
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
from Config import Config
|
from Config import Config
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
import os
|
|
||||||
|
import os, time
|
||||||
|
|
||||||
class AutoConf :
|
class AutoConf :
|
||||||
|
|
||||||
def __init__(self, swarm, api) :
|
def __init__(self, swarm, api) :
|
||||||
@ -20,7 +23,7 @@ class AutoConf :
|
|||||||
|
|
||||||
def __gen_env(self) :
|
def __gen_env(self) :
|
||||||
self.__env.clear()
|
self.__env.clear()
|
||||||
# TODO : check actual state (e.g. : running ?)
|
# TODO : check actual state (e.g. : running, stopped ?)
|
||||||
for id, instance in self.__instances.items() :
|
for id, instance in self.__instances.items() :
|
||||||
env = []
|
env = []
|
||||||
if self.__swarm :
|
if self.__swarm :
|
||||||
@ -94,16 +97,29 @@ class AutoConf :
|
|||||||
if event == "create" :
|
if event == "create" :
|
||||||
self.__instances[id] = instance
|
self.__instances[id] = instance
|
||||||
self.__gen_env()
|
self.__gen_env()
|
||||||
|
utils.log("[*] bunkerized-nginx instance created : " + name + " / " + id)
|
||||||
if self.__swarm and len(self.__instances) == 1 :
|
if self.__swarm and len(self.__instances) == 1 :
|
||||||
if self.__config.generate(self.__env) :
|
if self.__config.generate(self.__env) :
|
||||||
utils.log("[*] Initial config succeeded")
|
utils.log("[*] Initial config succeeded")
|
||||||
if not self.__config.swarm_wait(self.__instances) :
|
if not self.__config.swarm_wait(self.__instances) :
|
||||||
utils.log("[!] Removing bunkerized-nginx instances from list")
|
utils.log("[!] Removing bunkerized-nginx instances from list (API not available)")
|
||||||
del self.__instances[id]
|
del self.__instances[id]
|
||||||
else :
|
else :
|
||||||
utils.log("[!] Initial config failed")
|
utils.log("[!] Initial config failed")
|
||||||
# TODO : wait while unhealthy if not swarm
|
elif not self.__swarm and len(self.__instances) == 1 :
|
||||||
utils.log("[*] bunkerized-nginx instance created : " + name + " / " + id)
|
utils.log("[*] Wait until bunkerized-nginx is healthy (timeout = 120s) ...")
|
||||||
|
i = 0
|
||||||
|
healthy = False
|
||||||
|
while i < 120 :
|
||||||
|
self.__instances[id].reload()
|
||||||
|
if self.__instances[id].attrs["State"]["Health"]["Status"] == "healthy" :
|
||||||
|
healthy = True
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
i = i + 1
|
||||||
|
if not healthy :
|
||||||
|
utils.log("[!] Removing bunkerized-nginx instances from list (unhealthy)")
|
||||||
|
del self.__instances[id]
|
||||||
|
|
||||||
elif event == "start" :
|
elif event == "start" :
|
||||||
self.__instances[id].reload()
|
self.__instances[id].reload()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user