예제 #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)

    # 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()

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

    # Leave the harder restarts to the polling in SABnzbd.py
    if sabnzbd.WIN_SERVICE or getattr(sys, 'frozen', None) == 'macosx_app':
        sabnzbd.TRIGGER_RESTART = True
    else:
        # Do the restart right now
        cherrypy.engine._do_execv()
예제 #2
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)

    # 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()

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

    # Leave the harder restarts to the polling in SABnzbd.py
    if sabnzbd.WIN_SERVICE or getattr(sys, 'frozen', None) == 'macosx_app':
        sabnzbd.TRIGGER_RESTART = True
    else:
        # Do the restart right now
        cherrypy.engine._do_execv()
예제 #3
0
파일: __init__.py 프로젝트: 12345z/sabnzbd
def sig_handler(signum = None, frame = None):
    global SABSTOP
    if sabnzbd.WIN32 and type(signum) != type(None) and DAEMON and signum==5:
        # Ignore the "logoff" event when running as a Win32 daemon
        return True
    if type(signum) != type(None):
        logging.warning(Ta('Signal %s caught, saving and exiting...'), signum)
    try:
        save_state(flag=True)
    finally:
        if sabnzbd.WIN32:
            from util.apireg import del_connection_info
            del_connection_info()
        else:
            pid_file()
        SABSTOP = True
        os._exit(0)
예제 #4
0
def sig_handler(signum=None, frame=None):
    global SABSTOP
    if sabnzbd.WIN32 and type(signum) != type(None) and DAEMON and signum == 5:
        # Ignore the "logoff" event when running as a Win32 daemon
        return True
    if type(signum) != type(None):
        logging.warning(Ta('Signal %s caught, saving and exiting...'), signum)
    try:
        save_state(flag=True)
    finally:
        if sabnzbd.WIN32:
            from util.apireg import del_connection_info
            del_connection_info()
        else:
            pid_file()
        SABSTOP = True
        os._exit(0)
예제 #5
0
def trigger_restart():
    """ Trigger a restart by setting a flag an shutting down CP """
    if sabnzbd.downloader.Downloader.do.paused:
        sabnzbd.RESTART_ARGS.append('-p')
    sys.argv = sabnzbd.RESTART_ARGS

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

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

    # Leave the harder restarts to the polling in SABnzbd.py
    if sabnzbd.WIN_SERVICE or getattr(sys, 'frozen', None) == 'macosx_app':
        sabnzbd.TRIGGER_RESTART = True
    else:
        # Do the restart right now
        cherrypy.engine._do_execv()
예제 #6
0
def trigger_restart():
    """ Trigger a restart by setting a flag an shutting down CP """
    if sabnzbd.downloader.Downloader.do.paused:
        sabnzbd.RESTART_ARGS.append('-p')
    sys.argv = sabnzbd.RESTART_ARGS

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

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

    # Leave the harder restarts to the polling in SABnzbd.py
    if sabnzbd.WIN_SERVICE or getattr(sys, 'frozen', None) == 'macosx_app':
        sabnzbd.TRIGGER_RESTART = True
    else:
        # Do the restart right now
        cherrypy.engine._do_execv()
예제 #7
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:
            from util.apireg import del_connection_info
            del_connection_info()
            if sabnzbd.WINTRAY:
                sabnzbd.WINTRAY.terminate = True
                time.sleep(0.5)
        else:
            pid_file()
        SABSTOP = True
        os._exit(0)
예제 #8
0
def sig_handler(signum=None, frame=None):
    global SABSTOP, WINTRAY
    if sabnzbd.WIN32 and type(signum) != type(None) and DAEMON and signum == 5:
        # Ignore the "logoff" event when running as a Win32 daemon
        return True
    if type(signum) != type(None):
        logging.warning(T('Signal %s caught, saving and exiting...'), signum)
    try:
        save_state()
        sabnzbd.zconfig.remove_server()
    finally:
        if sabnzbd.WIN32:
            from util.apireg import del_connection_info
            del_connection_info()
            if sabnzbd.WINTRAY:
                sabnzbd.WINTRAY.terminate = True
                time.sleep(0.5)
        else:
            pid_file()
        SABSTOP = True
        os._exit(0)
예제 #9
0
def main():

    mail = MailSlot()
    if not mail.create(10):
        return '- Cannot create Mailslot'

    active = False  # SABnzbd should be running
    counter = 0  # Time allowed for SABnzbd to be silent
    while True:
        msg = mail.receive()
        if msg:
            if msg == 'restart':
                time.sleep(1.0)
                counter = 0
                del_connection_info(user=False)
                start_sab()
            elif msg == 'stop':
                active = False
                del_connection_info(user=False)
            elif msg == 'active':
                active = True
                counter = 0
            elif msg.startswith('api '):
                active = True
                counter = 0
                _cmd, url = msg.split()
                if url:
                    set_connection_info(url.strip(), user=False)

        if active:
            counter += 1
            if counter > 120:  # 120 seconds
                counter = 0
                start_sab()

        rc = win32event.WaitForMultipleObjects(
            (WIN_SERVICE.hWaitStop, WIN_SERVICE.overlapped.hEvent), 0, 1000)
        if rc == win32event.WAIT_OBJECT_0:
            del_connection_info(user=False)
            mail.disconnect()
            return ''
예제 #10
0
파일: SABHelper.py 프로젝트: 12345z/sabnzbd
def main():

    mail = MailSlot()
    if not mail.create(10):
        return '- Cannot create Mailslot'

    active = False  # SABnzbd should be running
    counter = 0     # Time allowed for SABnzbd to be silent
    while True:
        msg = mail.receive()
        if msg:
            if msg == 'restart':
                time.sleep(1.0)
                counter = 0
                del_connection_info(user=False)
                start_sab()
            elif msg == 'stop':
                active = False
                del_connection_info(user=False)
            elif msg == 'active':
                active = True
                counter = 0
            elif msg.startswith('api '):
                active = True
                counter = 0
                cmd, url = msg.split()
                if url:
                    set_connection_info(url.strip(), user=False)

        if active:
            counter += 1
            if counter > 120: # 120 seconds
                counter = 0
                start_sab()

        rc = win32event.WaitForMultipleObjects((WIN_SERVICE.hWaitStop,
             WIN_SERVICE.overlapped.hEvent), 0, 1000)
        if rc == win32event.WAIT_OBJECT_0:
            del_connection_info(user=False)
            mail.disconnect()
            return ''