Beispiel #1
0
    def start(self):
        super(Web, self).start()

        from deluge.ui.web import server
        self.__server = server.DelugeWeb(options=self.options)

        def run():
            try:
                self.server.install_signal_handlers()
                self.server.start()
            except CannotListenError as ex:
                log.error(
                    '%s \nCheck that deluge-web or webui plugin is not already running.',
                    ex)
            except Exception as ex:
                log.exception(ex)
                raise

        run_profiled(run,
                     output_file=self.options.profile,
                     do_profile=self.options.profile)
Beispiel #2
0
def start_daemon(skip_start=False):
    """
    Entry point for daemon script

    Args:
        skip_start (bool): If starting daemon should be skipped.

    Returns:
        deluge.core.daemon.Daemon: A new daemon object

    """
    set_dummy_trans(warn_msg=True)

    # Setup the argument parser
    parser = BaseArgParser()
    add_daemon_options(parser)

    options = parser.parse_args()

    # Check for any daemons running with this same config
    from deluge.core.daemon import is_daemon_running
    pid_file = get_config_dir('deluged.pid')
    if is_daemon_running(pid_file):
        print('Cannot run multiple daemons with same config directory.\n'
              'If you believe this is an error, force starting by deleting: %s' % pid_file)
        sys.exit(1)

    log = getLogger(__name__)

    # If no logfile specified add logging to default location (as well as stdout)
    if not options.logfile:
        options.logfile = get_config_dir('deluged.log')
        file_handler = FileHandler(options.logfile)
        log.addHandler(file_handler)

    def run_daemon(options):
        try:
            from deluge.core.daemon import Daemon
            daemon = Daemon(listen_interface=options.listen_interface,
                            interface=options.ui_interface,
                            port=options.port,
                            read_only_config_keys=options.read_only_config_keys.split(','))
            if skip_start:
                return daemon
            else:
                daemon.start()
        except CannotListenError as ex:
            log.error('Cannot start deluged, listen port in use.\n'
                      ' Check for other running daemons or services using this port: %s:%s',
                      ex.interface, ex.port)
            sys.exit(1)
        except Exception as ex:
            log.error('Unable to start deluged: %s', ex)
            if log.isEnabledFor(DEBUG):
                log.exception(ex)
            sys.exit(1)
        finally:
            log.info('Exiting...')
            if options.pidfile:
                os.remove(options.pidfile)

    return run_profiled(run_daemon, options, output_file=options.profile, do_profile=options.profile)