earlier init autoconf in DB, healthcheck for scheduler and fix syntax error in linux/start.sh

This commit is contained in:
bunkerity 2023-03-24 11:28:08 +01:00
parent 54813ecd4d
commit 4f9748cc2e
10 changed files with 31 additions and 8 deletions

View File

@ -75,6 +75,14 @@ class Controller(ABC):
def _get_static_services(self):
pass
def _set_autoconf_load_db():
if not self._config._db.is_autoconf_loaded():
ret = self._config._db.set_autoconf_load(True)
if ret:
self.__logger.warning(
f"Can't set autoconf loaded metadata to true in database: {ret}",
)
def get_services(self):
services = []
for controller_service in self._get_controller_services():

View File

@ -112,6 +112,7 @@ class DockerController(Controller, ConfigCaller):
)
def process_events(self):
self._set_autoconf_load_db()
for _ in self.__client.events(decode=True, filters={"type": "container"}):
try:
self._instances = self.get_instances()

View File

@ -282,6 +282,7 @@ class IngressController(Controller, ConfigCaller):
)
def process_events(self):
self._set_autoconf_load_db()
watch_types = ("pod", "ingress", "configmap")
threads = [
Thread(target=self.__watch, args=(watch_type,))

View File

@ -142,12 +142,6 @@ class SwarmController(Controller, ConfigCaller):
"Successfully deployed new configuration 🚀",
)
if not self._config._db.is_autoconf_loaded():
ret = self._config._db.set_autoconf_load(True)
if ret:
self.__logger.warning(
f"Can't set autoconf loaded metadata to true in database: {ret}",
)
except:
self.__logger.error(
f"Exception while processing events :\n{format_exc()}"
@ -155,6 +149,7 @@ class SwarmController(Controller, ConfigCaller):
self.__internal_lock.release()
def process_events(self):
self._set_autoconf_load_db()
event_types = ("service", "config")
threads = [
Thread(target=self.__event, args=(event_type,))

View File

@ -0,0 +1,11 @@
#!/bin/bash
if [ ! -f /var/tmp/bunkerweb/scheduler.pid ] ; then
exit 1
fi
if [ ! -f /var/tmp/bunkerweb/scheduler.healthy ] ; then
exit 1
fi
exit 0

View File

@ -88,7 +88,7 @@ function start() {
stop_nginx
# Generate temp conf for jobs and start nginx
if [ ! -f /var/tmp/bunkerweb/tmp.env] ; then
if [ ! -f /var/tmp/bunkerweb/tmp.env ] ; then
echo -ne "IS_LOADING=yes\nHTTP_PORT=80\nHTTPS_PORT=443\nAPI_LISTEN_IP=127.0.0.1\nSERVER_NAME=\n" > /var/tmp/bunkerweb/tmp.env
fi
/usr/share/bunkerweb/gen/main.py --variables /var/tmp/bunkerweb/tmp.env

View File

@ -72,4 +72,6 @@ WORKDIR /usr/share/bunkerweb/scheduler
USER scheduler:scheduler
HEALTHCHECK --interval=10s --timeout=10s --start-period=30s --retries=6 CMD /usr/share/bunkerweb/helpers/healthcheck-scheduler.sh
ENTRYPOINT ["/usr/share/bunkerweb/scheduler/entrypoint.sh"]

View File

@ -48,5 +48,8 @@ while [ -f /var/tmp/bunkerweb/scheduler.pid ] ; do
wait "$pid"
done
if [ -f /var/tmp/bunkerweb/scheduler.healthy ] ; then
rm /var/tmp/bunkerweb/scheduler.healthy
fi
log "ENTRYPOINT" " " "Scheduler stopped"
exit 0

View File

@ -85,6 +85,7 @@ signal(SIGHUP, handle_reload)
def stop(status):
Path("/var/tmp/bunkerweb/scheduler.pid").unlink(missing_ok=True)
Path("/var/tmp/bunkerweb/scheduler.healthy").unlink(missing_ok=True)
_exit(status)
@ -414,6 +415,7 @@ if __name__ == "__main__":
# infinite schedule for the jobs
logger.info("Executing job scheduler ...")
Path("/var/tmp/bunkerweb/scheduler.healthy").write_text("ok")
while run and not need_reload:
scheduler.run_pending()
sleep(1)

View File

@ -63,7 +63,7 @@ class LinuxTest(Test):
LinuxTest.docker_exec(
distro, "systemctl stop php7.4-fpm ; systemctl start php7.4-fpm"
)
elif distro in ("centos", "fedora"):
elif distro in ("centos", "fedora", "rhel"):
LinuxTest.docker_exec(distro, "dnf install -y php-fpm unzip")
LinuxTest.docker_cp(
distro, "./tests/www-rpm.conf", "/etc/php-fpm.d/www.conf"