Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aikido_zen/background_process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def start_background_process():

# Daemon is set to True so that the process kills itself when the main process dies
background_process = Process(
target=AikidoBackgroundProcess, args=(comms.address, comms.key), daemon=True
target=AikidoBackgroundProcess,
args=(comms.address, comms.key),
name="zen-agent-process",
daemon=True,
)
background_process.start()

Expand Down
19 changes: 18 additions & 1 deletion aikido_zen/background_process/aikido_background_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import multiprocessing.connection as con
import signal
import time
import sched
import traceback
Expand Down Expand Up @@ -40,12 +41,14 @@ def __init__(self, address, key):
self.queue = Queue()
self.connection_manager = None
# Start reporting thread :
Thread(target=self.reporting_thread).start()
Thread(target=self.reporting_thread, daemon=True).start()

logger.debug(
"Background process started successfully, with UDS File : %s", address
)

add_exit_handlers()

while True:
conn = listener.accept()
while True:
Expand Down Expand Up @@ -105,3 +108,17 @@ def send_to_connection_manager(self, event_scheduler):
blocked=queue_attack_item[2],
stack=queue_attack_item[3],
)


def add_exit_handlers():
"""
We add graceful exit handlers here since the process keeps hanging otherwise.
"""

def exit_gracefully(sig, frame):
sys.exit(0)

signal.signal(signal.SIGINT, exit_gracefully)
signal.signal(signal.SIGTERM, exit_gracefully)
signal.signal(signal.SIGQUIT, exit_gracefully)
signal.signal(signal.SIGHUP, exit_gracefully)
6 changes: 1 addition & 5 deletions aikido_zen/decorators/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
import aikido_zen


# Run our background process as a child of gunicorn (exits safely)
aikido_zen.protect("daemon_only")


def post_fork(prev_func):
"""
Aikido decorator for gunicorn config
Function: post_fork(server, worker)
"""

def aik_post_fork(server, worker):
aikido_zen.protect("daemon_disabled")
aikido_zen.protect()
prev_func(server, worker)

return aik_post_fork
Loading