def signal_handler(n_signal, frame): def strsignal(n_signal): libc = ctypes.CDLL(ctypes.util.find_library('c')) strsignal_proto = ctypes.CFUNCTYPE(ctypes.c_char_p, ctypes.c_int) strsignal_c = strsignal_proto(("strsignal", libc), ((1, ), )) return strsignal_c(n_signal) logging.info("Signal [{0}-{1}] received. Exit cleaning...".format( n_signal, strsignal(n_signal))) # received Cntrl+C if n_signal == SIGINT: # kill C daemon if it's running try: pid = int( check_output([ "pidof", "{0}/framework/wazuh-clusterd-internal".format(ossec_path) ])) kill(pid, SIGINT) except CalledProcessError: pass if child_pid != 0: # remove pid files delete_pid("wazuh-clusterd", getpid()) exit(1)
def signal_handler(n_signal, frame): def strsignal(n_signal): libc = ctypes.CDLL(ctypes.util.find_library('c')) strsignal_proto = ctypes.CFUNCTYPE(ctypes.c_char_p, ctypes.c_int) strsignal_c = strsignal_proto(("strsignal", libc), ((1, ), )) return strsignal_c(n_signal) logging.info("Signal [{0}-{1}] received. Exit cleaning...".format( n_signal, strsignal(n_signal))) # received Cntrl+C if n_signal == SIGINT or n_signal == SIGTERM: # kill C daemon if it's running try: pid = int( check_output([ "pidof", "{0}/bin/wazuh-clusterd-internal".format(ossec_path) ])) kill(pid, SIGINT) except Exception: pass if child_pid != 0: try: # kill child kill(child_pid, SIGTERM) # remove pid files delete_pid("wazuh-clusterd", getpid()) except Exception as e: logging.error("Error killing child process: {}".format(str(e))) if args.d: raise exit(1)
def signal_handler(n_signal, frame): def strsignal(n_signal): libc = ctypes.CDLL(ctypes.util.find_library('c')) strsignal_proto = ctypes.CFUNCTYPE(ctypes.c_char_p, ctypes.c_int) strsignal_c = strsignal_proto(("strsignal", libc), ((1, ), )) return strsignal_c(n_signal) logging.info("Signal [{0}-{1}] received. Exit cleaning...".format( n_signal, strsignal(n_signal))) # received Cntrl+C if n_signal == SIGINT or n_signal == SIGTERM: # kill C daemon if it's running try: pid = int( check_output([ "pidof", "{0}/bin/wazuh-clusterd-internal".format(common.ossec_path) ])) kill(pid, SIGINT) except Exception: pass if child_pid != 0: try: # kill child kill(child_pid, SIGTERM) # remove pid files delete_pid("wazuh-clusterd", getpid()) except Exception as e: logging.error("Error killing child process: {0}".format( str(e))) if args.d: raise else: for connections in common.cluster_connections.values(): try: logging.debug("Closing socket {0}...".format( connections.socket.getpeername())) connections.socket.close() except socket.error as e: if e.errno == socket.errno.EBADF: logging.debug("Socket already closed: {0}".format( str(e))) else: logging.error("Could not close socket: {0}".format( str(e))) exit(1)
def clean_exit(reason, error=False): global processing_exit if not processing_exit: processing_exit = True msg = "[{0}] Exiting. Reason: '{1}'.".format(manager_tag, reason) if error: logger.error(msg) else: logger.info(msg) if manager: manager.exit() delete_pid("wazuh-clusterd", getpid()) exit(1) else: logger.debug2("[{0}] clean_exit was already executed. Skipping.".format(manager_tag))