示例#1
0
def trigger_restart(timeout=None):
    """ Trigger a restart by setting a flag an shutting down CP """
    # Sometimes we need to wait a bit to send good-bye to the browser
    if timeout:
        time.sleep(timeout)

    if sabnzbd.WIN32:
        # Remove connection info for faster restart
        del_connection_info()

    # Leave the harder restarts to the polling in SABnzbd.py
    if hasattr(sys, "frozen"):
        sabnzbd.TRIGGER_RESTART = True
    else:
        # Add extra arguments
        if sabnzbd.downloader.Downloader.do.paused:
            sabnzbd.RESTART_ARGS.append("-p")
        sys.argv = sabnzbd.RESTART_ARGS

        # Stop all services
        sabnzbd.halt()
        cherrypy.engine.exit()

        # Do the restart right now
        cherrypy.engine._do_execv()
示例#2
0
    def test_set_get_connection_info_user(self):
        """ Test the saving of the URL in USER-registery
            We can't test the SYSTEM one.
        """

        test_url = "sab_test:8080"
        ar.set_connection_info(test_url, True)
        assert ar.get_connection_info(True) == test_url
        assert not ar.get_connection_info(False)

        # Remove and check if gone
        ar.del_connection_info(True)
        assert not ar.get_connection_info(True)
示例#3
0
def sig_handler(signum=None, frame=None):
    global SABSTOP, WINTRAY
    if sabnzbd.WIN32 and signum is not None and DAEMON and signum == 5:
        # Ignore the "logoff" event when running as a Win32 daemon
        return True
    if signum is not None:
        logging.warning(T("Signal %s caught, saving and exiting..."), signum)
    try:
        save_state()
        sabnzbd.zconfig.remove_server()
    finally:
        if sabnzbd.WIN32:
            del_connection_info()
            if sabnzbd.WINTRAY:
                sabnzbd.WINTRAY.terminate = True
                time.sleep(0.5)
        else:
            pid_file()
        SABSTOP = True
        os._exit(0)
示例#4
0
def halt():
    if sabnzbd.__INITIALIZED__:
        logging.info("SABnzbd shutting down...")
        sabnzbd.__SHUTTING_DOWN__ = True

        # Stop the windows tray icon
        if sabnzbd.WINTRAY:
            sabnzbd.WINTRAY.stop()

        # Remove registry information
        if sabnzbd.WIN32:
            del_connection_info()

        sabnzbd.zconfig.remove_server()
        sabnzbd.utils.ssdp.stop_ssdp()

        sabnzbd.directunpacker.abort_all()

        logging.debug("Stopping RSSReader")
        sabnzbd.RSSReader.stop()

        logging.debug("Stopping URLGrabber")
        sabnzbd.URLGrabber.stop()
        try:
            sabnzbd.URLGrabber.join()
        except:
            pass

        logging.debug("Stopping rating")
        sabnzbd.Rating.stop()
        try:
            sabnzbd.Rating.join()
        except:
            pass

        logging.debug("Stopping dirscanner")
        sabnzbd.DirScanner.stop()
        try:
            sabnzbd.DirScanner.join()
        except:
            pass

        logging.debug("Stopping downloader")
        sabnzbd.Downloader.stop()
        try:
            sabnzbd.Downloader.join()
        except:
            pass

        # Decoder handles join gracefully
        logging.debug("Stopping decoders")
        sabnzbd.Decoder.stop()
        sabnzbd.Decoder.join()

        logging.debug("Stopping assembler")
        sabnzbd.Assembler.stop()
        try:
            sabnzbd.Assembler.join()
        except:
            pass

        logging.debug("Stopping postprocessor")
        sabnzbd.PostProcessor.stop()
        try:
            sabnzbd.PostProcessor.join()
        except:
            pass

        # Save State
        try:
            save_state()
        except:
            logging.error(T("Fatal error at saving state"), exc_info=True)

        # The Scheduler cannot be stopped when the stop was scheduled.
        # Since all warm-restarts have been removed, it's not longer
        # needed to stop the scheduler.
        # We must tell the scheduler to deactivate.
        logging.debug("Terminating scheduler")
        sabnzbd.Scheduler.abort()

        logging.info("All processes stopped")

        sabnzbd.__INITIALIZED__ = False