Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Szefler committed Dec 13, 2023
1 parent 96201f8 commit cb9c124
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/robusta/runner/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import signal

from robusta.core.model.env_vars import (
Expand All @@ -13,24 +12,15 @@
from robusta.patch.patch import create_monkey_patches
from robusta.runner.config_loader import ConfigLoader
from robusta.runner.log_init import init_logging, logging
from robusta.runner.process_setup import process_setup
from robusta.runner.ssl_utils import add_custom_certificate
from robusta.runner.telemetry_service import TelemetryLevel, TelemetryService
from robusta.runner.web import Web
from robusta.utils.server_start import ServerStart


def main():
if os.fork():
# parent process, pid 1 in our deployment scenario. Wait for the forked "main"
# process to exit (if it ever does) and exit ourselves, effectively causing
# the image to terminate.
os.wait()
return

# child process; create a process group to conveniently terminate the process
# along with subprocesses if need be
os.setpgrp()

process_setup()
init_logging()
ServerStart.set()
if add_custom_certificate(ADDITIONAL_CERTIFICATE):
Expand Down
17 changes: 17 additions & 0 deletions src/robusta/runner/process_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import sys


def process_setup():
if os.fork():
# Parent process, pid 1 in our deployment scenario. Wait (blocking - doesn't
# utilitze any CPU) for the forked "main" process to exit (if it ever does)
os.wait()
# At this point we are sure no subprocesses are running, so we can safely
# exit the pid 1 process, effectively causing the image to terminate.
sys.exit(1)

# Child process; create a process group to conveniently terminate the process
# along with subprocesses if need be via killpg. Currently the only use is in
# robusta.runner.config_loader.ConfigLoader.__reload_playbook_packages.
os.setpgrp()

0 comments on commit cb9c124

Please sign in to comment.