Beispiel #1
0
def main(args):
    logger.info("Starting up")
    daemon = None
    shutdown_sig = threading.Event()

    def _sig_handler(sig, frame):
        logger.debug("Handler received signal %s", sig)
        if sig in (signal.SIGTERM, signal.SIGKILL, signal.SIGINT):
            shutdown_sig.set()
            daemon.stop()

    signal.signal(signal.SIGUSR1, _sig_handler)
    signal.signal(signal.SIGINT, _sig_handler)

    error = False

    try:
        daemon = AmavisVTDaemon(socket_path=args.socket)
        daemon.run_and_wait()

        while True:
            shutdown_sig.wait(5)
            if shutdown_sig.is_set():
                break
    except KeyboardInterrupt:
        error = True
    except:
        logger.exception("Server error")
        error = True
    finally:
        if daemon:
            daemon.stop()

    return error
Beispiel #2
0
 def test_stop_do_nothing(self, os_mock):
     d = AmavisVTDaemon('dummy-socket')
     d.server = mock.MagicMock()
     d.stop()
     assert d.server.shutdown.called
     assert d.server.server_close.called
     os_mock.remove.assert_called_with('dummy-socket')
Beispiel #3
0
 def test_stop_do_nothing(self, os_mock):
     d = AmavisVTDaemon('dummy-socket')
     d.server = mock.MagicMock()
     d.stop()
     assert d.server.shutdown.called
     assert d.server.server_close.called
     os_mock.remove.assert_called_with('dummy-socket')
Beispiel #4
0
def main(args):
    logger.info("Starting up")
    daemon = None
    shutdown_sig = threading.Event()

    def _sig_handler(sig, frame):
        logger.debug("Handler received signal %s", sig)
        if sig in (signal.SIGTERM, signal.SIGKILL, signal.SIGINT):
            shutdown_sig.set()
            daemon.stop()

    signal.signal(signal.SIGUSR1, _sig_handler)
    signal.signal(signal.SIGINT, _sig_handler)

    error = False

    try:
        daemon = AmavisVTDaemon(socket_path=args.socket)
        daemon.run_and_wait()

        while True:
            shutdown_sig.wait(5)
            if shutdown_sig.is_set():
                break
    except KeyboardInterrupt:
        error = True
    except:
        logger.exception("Server error")
        error = True
    finally:
        if daemon:
            daemon.stop()

    return error
Beispiel #5
0
 def test_stop_do_nothing(self):
     d = AmavisVTDaemon('dummy-socket')
     d.stop()
     assert True
Beispiel #6
0
 def test_is_socket_working_error(self):
     d = AmavisVTDaemon('dummy-socket')
     assert not d.is_socket_working('dummy-socket')
Beispiel #7
0
 def test_stop_do_nothing(self):
     d = AmavisVTDaemon('dummy-socket')
     d.stop()
     assert True
Beispiel #8
0
 def test_is_socket_working_error(self):
     d = AmavisVTDaemon('dummy-socket')
     assert not d.is_socket_working('dummy-socket')