diff --git a/src/start_fact_backend.py b/src/start_fact_backend.py index 590a92609..bdf72148e 100755 --- a/src/start_fact_backend.py +++ b/src/start_fact_backend.py @@ -20,6 +20,7 @@ import grp import logging import os +import resource import sys from pathlib import Path @@ -37,6 +38,8 @@ from scheduler.unpacking_scheduler import UnpackingScheduler from storage.unpacking_locks import UnpackingLockManager +ULIMIT_MIN = 2048 + class FactBackend(FactBase): PROGRAM_NAME = 'FACT Backend' @@ -47,6 +50,7 @@ def __init__(self): super().__init__() self.unpacking_lock_manager = UnpackingLockManager() self._create_docker_base_dir() + _check_ulimit() try: self.analysis_service = AnalysisScheduler(unpacking_locks=self.unpacking_lock_manager) @@ -110,6 +114,20 @@ def _exception_occurred(self): ) +def _check_ulimit(): + soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE) + if hard_limit < ULIMIT_MIN: + logging.critical( + f'The open file limit must be set to at least {ULIMIT_MIN} (ideally 10000 or more, depending on the ' + 'number of worker processes) so that the backend of FACT can work without errors. Please increase the ' + 'open file limit (e.g. by running `ulimit -n 9999` in this shell before starting FACT).' + ) + sys.exit(1) + if soft_limit < hard_limit: + # we are only allowed to increase the soft limit and not the hard limit + resource.setrlimit(resource.RLIMIT_NOFILE, (hard_limit, hard_limit)) + + if __name__ == '__main__': FactBackend().main() sys.exit(0)