forked from p15670423/monkey
Agent: register signal handlers
Agent will now handle interrupt and break signals on linux and windows
This commit is contained in:
parent
e00fd64530
commit
9d36f20b42
|
@ -38,6 +38,7 @@ from infection_monkey.utils.monkey_dir import (
|
||||||
remove_monkey_dir,
|
remove_monkey_dir,
|
||||||
)
|
)
|
||||||
from infection_monkey.utils.monkey_log_path import get_monkey_log_path
|
from infection_monkey.utils.monkey_log_path import get_monkey_log_path
|
||||||
|
from infection_monkey.utils.signal_handler import register_signal_handlers
|
||||||
from infection_monkey.windows_upgrader import WindowsUpgrader
|
from infection_monkey.windows_upgrader import WindowsUpgrader
|
||||||
|
|
||||||
MAX_DEPTH_REACHED_MESSAGE = "Reached max depth, skipping propagation phase."
|
MAX_DEPTH_REACHED_MESSAGE = "Reached max depth, skipping propagation phase."
|
||||||
|
@ -107,6 +108,8 @@ class InfectionMonkey(object):
|
||||||
logger.info("Monkey is starting...")
|
logger.info("Monkey is starting...")
|
||||||
|
|
||||||
logger.debug("Starting the setup phase.")
|
logger.debug("Starting the setup phase.")
|
||||||
|
register_signal_handlers()
|
||||||
|
input()
|
||||||
# Sets island's IP and port for monkey to communicate to
|
# Sets island's IP and port for monkey to communicate to
|
||||||
self.set_default_server()
|
self.set_default_server()
|
||||||
self.set_default_port()
|
self.set_default_port()
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import logging
|
||||||
|
import signal
|
||||||
|
|
||||||
|
from infection_monkey.utils.environment import is_windows_os
|
||||||
|
from infection_monkey.utils.exceptions.planned_shutdown_exception import PlannedShutdownException
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def stop_signal_handler(_, __):
|
||||||
|
# IMaster.cleanup()
|
||||||
|
logger.debug("Some kind of interrupt signal was sent to the Monkey Agent")
|
||||||
|
raise PlannedShutdownException("Monkey Agent got an interrupt signal")
|
||||||
|
|
||||||
|
|
||||||
|
def register_signal_handlers():
|
||||||
|
signal.signal(signal.SIGINT, stop_signal_handler)
|
||||||
|
signal.signal(signal.SIGTERM, stop_signal_handler)
|
||||||
|
|
||||||
|
if is_windows_os():
|
||||||
|
signal.signal(signal.SIGBREAK, stop_signal_handler)
|
Loading…
Reference in New Issue