autoconf - various bug fixes in Swarm mode
This commit is contained in:
parent
f866ef6325
commit
24d9cce82f
|
@ -12,6 +12,21 @@ class Config :
|
|||
self.__type = type
|
||||
self.__api_uri = api_uri
|
||||
|
||||
|
||||
def __jobs(self) :
|
||||
log("config", "INFO", "starting jobs ...")
|
||||
proc = subprocess.run(["/bin/su", "-c", "/opt/bunkerized-nginx/entrypoint/jobs.sh", "nginx"], capture_output=True)
|
||||
stdout = proc.stdout.decode("ascii")
|
||||
stderr = proc.stderr.decode("ascii")
|
||||
if len(stdout) > 1 :
|
||||
log("config", "INFO", "jobs stdout : " + stdout)
|
||||
if stderr != "" :
|
||||
log("config", "ERROR", "jobs stderr : " + stderr)
|
||||
if proc.returncode != 0 :
|
||||
log("config", "ERROR", "jobs error (return code = " + str(proc.returncode) + ")")
|
||||
return False
|
||||
return True
|
||||
|
||||
def gen(self, env) :
|
||||
try :
|
||||
# Write environment variables to a file
|
||||
|
|
|
@ -11,7 +11,7 @@ class Type(Enum) :
|
|||
class Controller(ABC) :
|
||||
|
||||
def __init__(self, type, api_uri=None, lock=None) :
|
||||
self.__config = Config(type, api_uri)
|
||||
self._config = Config(type, api_uri)
|
||||
self.lock = lock
|
||||
|
||||
@abstractmethod
|
||||
|
@ -27,7 +27,11 @@ class Controller(ABC) :
|
|||
return fixed_env
|
||||
|
||||
def gen_conf(self, env) :
|
||||
return self.__config.gen(env)
|
||||
return self._config.gen(env)
|
||||
|
||||
@abstractmethod
|
||||
def wait(self) :
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def process_events(self, current_env) :
|
||||
|
@ -38,4 +42,4 @@ class Controller(ABC) :
|
|||
pass
|
||||
|
||||
def _reload(self, instances) :
|
||||
return self.__config.reload(instances)
|
||||
return self._config.reload(instances)
|
||||
|
|
|
@ -57,3 +57,7 @@ class DockerController(Controller.Controller) :
|
|||
def reload(self) :
|
||||
return self._reload(self.__get_instances())
|
||||
|
||||
|
||||
def wait(self) :
|
||||
# TODO : healthcheck ?
|
||||
return True
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from kubernetes import client, config, watch
|
||||
from threading import Thread
|
||||
from threading import Thread, Lock
|
||||
|
||||
import Controller
|
||||
|
||||
|
@ -96,3 +96,6 @@ class IngressController(Controller.Controller) :
|
|||
|
||||
def reload(self) :
|
||||
return self._reload(self.__get_ingresses())
|
||||
|
||||
def wait(self) :
|
||||
return self._config.wait(self.__get_ingresses())
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import docker
|
||||
from threading import Lock
|
||||
|
||||
from logger import log
|
||||
|
||||
|
@ -59,3 +60,6 @@ class SwarmController(Controller.Controller) :
|
|||
|
||||
def reload(self) :
|
||||
return self._reload(self.__get_instances())
|
||||
|
||||
def wait(self) :
|
||||
return self._config.wait(self.__get_instances())
|
||||
|
|
|
@ -28,12 +28,18 @@ else :
|
|||
|
||||
# Run the reload server in background if needed
|
||||
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 != {} :
|
||||
controller.gen_conf(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")
|
||||
|
||||
# Process events
|
||||
log("autoconf", "INFO", "waiting for events ...")
|
||||
controller.process_events(current_env)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
# /etc/letsencrypt
|
||||
if [ ! -r "/etc/letsencrypt" ] || [ ! -x "/etc/letsencrypt" ] ; then
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
# /etc/letsencrypt
|
||||
if [ ! -w "/etc/letsencrypt" ] || [ ! -r "/etc/letsencrypt" ] || [ ! -x "/etc/letsencrypt" ] ; then
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import abc, requests, redis, os, datetime, traceback, re, shutil, enum, filecmp, subprocess
|
||||
import abc, requests, redis, os, datetime, traceback, re, shutil, enum, filecmp, subprocess, stat, socket
|
||||
|
||||
from logger import log
|
||||
|
||||
|
@ -19,9 +19,9 @@ class JobManagement() :
|
|||
if os.path.isfile("/usr/sbin/nginx") and os.path.isfile("/tmp/nginx.pid") :
|
||||
self.__local_nginx = True
|
||||
self.__autoconf_socket = None
|
||||
if os.path.exists("/tmp/autoconf.sock") and stat.S_ISSOCK(os.stat("/tmp/autoconf.sock")) :
|
||||
if os.path.exists("/tmp/autoconf.sock") and stat.S_ISSOCK(os.stat("/tmp/autoconf.sock").st_mode) :
|
||||
self.__autoconf_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.__autoconf_socket.connect()
|
||||
self.__autoconf_socket.connect("/tmp/autoconf.sock")
|
||||
|
||||
def __autoconf_order(self, order) :
|
||||
self.__autoconf_socket.sendall(order)
|
||||
|
|
Loading…
Reference in New Issue