Skip to content

Commit

Permalink
backend start script: check ulimit and increase soft limit if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Jul 3, 2024
1 parent b586eb6 commit cb8b26c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/start_fact_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import grp
import logging
import os
import resource
import sys
from pathlib import Path

Expand All @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit cb8b26c

Please sign in to comment.