1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-12 10:45:38 +02:00

Add a sigterm handler to make docker go faster

This commit is contained in:
Florent Daigniere 2023-11-07 16:55:24 +01:00
parent fd66c76c83
commit 1c26368b37

View File

@ -1,6 +1,7 @@
import hmac
import logging as log
import os
import signal
import sys
import re
from pwd import getpwnam
@ -69,11 +70,17 @@ def _is_compatible_with_hardened_malloc():
return False
return True
def sigterm_handler(_signo, _stack_frame):
log.error("Received SIGTERM, terminating.")
sys.exit(0)
def set_env(required_secrets=[], log_filters=[]):
if log_filters:
sys.stdout = LogFilter(sys.stdout, log_filters)
sys.stderr = LogFilter(sys.stderr, log_filters)
log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", 'WARNING'))
signal.signal(signal.SIGTERM, sigterm_handler)
if not 'LD_PRELOAD' in os.environ and _is_compatible_with_hardened_malloc():
log.warning('Your CPU has Advanced Vector Extensions available, we recommend you enable hardened-malloc earlier in the boot process by adding LD_PRELOAD=/usr/lib/libhardened_malloc.so to your mailu.env')