From cf75e3575c33249a6f756dceb423c6ec7f6cd50e Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 2 Jul 2014 12:14:22 -0300 Subject: Move the backend starter to its own file. --- src/leap/bitmask/backend_app.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/leap/bitmask/backend_app.py') diff --git a/src/leap/bitmask/backend_app.py b/src/leap/bitmask/backend_app.py index e69de29b..bd3b8a1f 100644 --- a/src/leap/bitmask/backend_app.py +++ b/src/leap/bitmask/backend_app.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# backend_app.py +# Copyright (C) 2013, 2014 LEAP +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import signal + +from leap.bitmask.backend.leapbackend import LeapBackend + + +def run_backend(bypass_checks=False): + # Ensure that the application quits using CTRL-C + signal.signal(signal.SIGINT, signal.SIG_DFL) + + backend = LeapBackend(bypass_checks=bypass_checks) + backend.run() -- cgit v1.2.3 From 0cab909f9518273d95e371e5fb1061fb9b0a92fd Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 2 Jul 2014 12:52:31 -0300 Subject: Send the flag module values to the processes. Add serialize/deserialize to dict helper. --- src/leap/bitmask/backend_app.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/leap/bitmask/backend_app.py') diff --git a/src/leap/bitmask/backend_app.py b/src/leap/bitmask/backend_app.py index bd3b8a1f..d4815d82 100644 --- a/src/leap/bitmask/backend_app.py +++ b/src/leap/bitmask/backend_app.py @@ -17,11 +17,22 @@ import signal from leap.bitmask.backend.leapbackend import LeapBackend +from leap.bitmask.util import dict_to_flags -def run_backend(bypass_checks=False): +def run_backend(bypass_checks, flags_dict): + """ + Run the backend for the application. + + :param bypass_checks: whether we should bypass the checks or not + :type bypass_checks: bool + :param flags_dict: a dict containing the flag values set on app start. + :type flags_dict: dict + """ # Ensure that the application quits using CTRL-C signal.signal(signal.SIGINT, signal.SIG_DFL) + dict_to_flags(flags_dict) + backend = LeapBackend(bypass_checks=bypass_checks) backend.run() -- cgit v1.2.3 From c3f485e194eb32939755178b11d472e1e69a94ad Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 2 Jul 2014 16:43:58 -0300 Subject: Handle SIGINT/SIGTERM in processes. --- src/leap/bitmask/backend_app.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/leap/bitmask/backend_app.py') diff --git a/src/leap/bitmask/backend_app.py b/src/leap/bitmask/backend_app.py index d4815d82..b6d00f2d 100644 --- a/src/leap/bitmask/backend_app.py +++ b/src/leap/bitmask/backend_app.py @@ -14,11 +14,32 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import logging +import multiprocessing import signal from leap.bitmask.backend.leapbackend import LeapBackend from leap.bitmask.util import dict_to_flags +logger = logging.getLogger(__name__) + + +def signal_handler(signum, frame): + """ + Signal handler that quits the running app cleanly. + + :param signum: number of the signal received (e.g. SIGINT -> 2) + :type signum: int + :param frame: current stack frame + :type frame: frame or None + """ + # Note: we don't stop the backend in here since the frontend signal handler + # will take care of that. + # In the future we may need to do the stop in here when the frontend and + # the backend are run separately (without multiprocessing) + pname = multiprocessing.current_process().name + logger.debug("{0}: SIGNAL #{1} catched.".format(pname, signum)) + def run_backend(bypass_checks, flags_dict): """ @@ -29,8 +50,9 @@ def run_backend(bypass_checks, flags_dict): :param flags_dict: a dict containing the flag values set on app start. :type flags_dict: dict """ - # Ensure that the application quits using CTRL-C - signal.signal(signal.SIGINT, signal.SIG_DFL) + # ignore SIGINT since app.py takes care of signaling SIGTERM to us. + signal.signal(signal.SIGINT, signal.SIG_IGN) + signal.signal(signal.SIGTERM, signal_handler) dict_to_flags(flags_dict) -- cgit v1.2.3 From d33e9a2bc07ccd983a1321b254cc27ca6be989a3 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 8 Jul 2014 17:01:18 -0300 Subject: Add file docstrings. --- src/leap/bitmask/backend_app.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/leap/bitmask/backend_app.py') diff --git a/src/leap/bitmask/backend_app.py b/src/leap/bitmask/backend_app.py index b6d00f2d..5c0e4803 100644 --- a/src/leap/bitmask/backend_app.py +++ b/src/leap/bitmask/backend_app.py @@ -14,6 +14,9 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +""" +Start point for the Backend. +""" import logging import multiprocessing import signal -- cgit v1.2.3