handle stop signals with the web-ui

This commit is contained in:
Théophile Diot 2022-12-07 11:18:02 +01:00
parent 064f9eef94
commit be0ee60cdd
No known key found for this signature in database
GPG Key ID: E752C80DB72BB014
1 changed files with 18 additions and 1 deletions

View File

@ -1,4 +1,5 @@
from io import BytesIO
from signal import SIGINT, signal, SIGTERM
from bs4 import BeautifulSoup
from copy import deepcopy
from datetime import datetime, timedelta, timezone
@ -25,7 +26,7 @@ from json import JSONDecodeError, dumps, load as json_load
from jinja2 import Template
from kubernetes import client as kube_client
from kubernetes.client.exceptions import ApiException as kube_ApiException
from os import chmod, getenv, getpid, listdir, mkdir, walk
from os import _exit, chmod, getenv, getpid, listdir, mkdir, remove, walk
from os.path import exists, isdir, isfile, join
from re import match as re_match
from requests import get
@ -60,6 +61,22 @@ from Database import Database
logger = setup_logger("UI", getenv("LOG_LEVEL", "INFO"))
def stop(status):
remove("/var/tmp/bunkerweb/ui.pid")
_exit(status)
def handle_stop(signum, frame):
logger.info("Catched stop operation")
logger.info("Stopping web ui ...")
stop(0)
signal(SIGINT, handle_stop)
signal(SIGTERM, handle_stop)
# Flask app
app = Flask(
__name__,