Example #1
0
    def start(self):
        self.log('web2py server starting')
        if not self.chdir():
            return
        if len(sys.argv) == 2:
            opt_mod = sys.argv[1]
        else:
            opt_mod = self._exe_args_
        options = __import__(opt_mod, [], [], '')
        from main import HttpServer
        self.server = HttpServer(
            ip=options.ip,
            port=options.port,
            password=options.password,
            pid_filename=options.pid_filename,
            log_filename=options.log_filename,
            profiler_filename=options.profiler_filename,
            ssl_certificate=options.ssl_certificate,
            ssl_private_key=options.ssl_private_key,
            numthreads=options.numthreads,
            server_name=options.server_name,
            request_queue_size=options.request_queue_size,
            timeout=options.timeout,
            shutdown_timeout=options.shutdown_timeout,
            path=options.folder,
        )
        try:
            self.server.start()
        except:

            # self.server.stop()

            self.server = None
            raise
Example #2
0
    def start(self):
        self.log('web2py server starting')
        if not self.chdir():
            return
        if len(sys.argv) == 2:
            opt_mod = sys.argv[1]
        else:
            opt_mod = self._exe_args_
        options = __import__(opt_mod, [], [], '')
        from main import HttpServer
        self.server = HttpServer(
            ip=options.ip,
            port=options.port,
            password=options.password,
            pid_filename=options.pid_filename,
            log_filename=options.log_filename,
            profiler_filename=options.profiler_filename,
            ssl_certificate=options.ssl_certificate,
            ssl_private_key=options.ssl_private_key,
            numthreads=options.numthreads,
            server_name=options.server_name,
            request_queue_size=options.request_queue_size,
            timeout=options.timeout,
            shutdown_timeout=options.shutdown_timeout,
            path=options.folder,
            )
        try:
            self.server.start()
        except:

            # self.server.stop()

            self.server = None
            raise
Example #3
0
def start(cron = True):
    """ Start server  """

    # ## get command line arguments

    (options, args) = console()
    print ProgramName
    print ProgramAuthor
    print ProgramVersion

    from sql import drivers
    print 'Database drivers available: %s' % ', '.join(drivers)

    # ## Starts cron daemon

    if cron and not options.nocron:
        print 'Starting cron...'
        contrib.cron.crontype = 'hard'
        cron = contrib.cron.hardcron()
        cron.start()

    # ## if -W install/start/stop web2py as service

    if options.winservice:
        if os.name == 'nt':
            web2py_windows_service_handler(['', options.winservice],
                    options.config)
        else:
            print 'Error: Windows services not supported on this platform'
            sys.exit(1)
        return

    # ## if -T run doctests

    if options.test:
        test(options.test, verbose=options.verbose)
        return

    # ## if -S start interactive shell

    if options.shell:
        run(options.shell, plain=options.plain,
            import_models=options.import_models, startfile=options.run)
        return

    # ## if -L load options from options.config file

    if options.config:
        try:
            options = __import__(options.config, [], [], '')
        except Exception:
            print 'Cannot import config file [%s]' % options.config
            sys.exit(1)

    # ## if -C start cron run
    # ## if -N disable cron in this *process*
    # ##     - note, startup tasks WILL be run regardless !

    if options.extcron or options.nocron:
        contrib.cron.crontype = 'External'
        if options.extcron:
            cron = contrib.cron.extcron()
            cron.start()
            cron.join()
            return

    # ## if no password provided and havetk start Tk interface
    # ## or start interface if we want to put in taskbar (system tray)

    try:
        options.taskbar
    except:
        options.taskbar = False

    if options.taskbar and os.name != 'nt':
        print 'Error: taskbar not supported on this platform'
        sys.exit(1)

    root = None

    if options.password == '<ask>' and havetk or options.taskbar and havetk:
        try:
            root = Tkinter.Tk()
        except:
            pass

    if root:
        root.focus_force()
        if not options.quiet:
            presentation(root)
        master = web2pyDialog(root, options)
        signal.signal(signal.SIGTERM, lambda a, b: master.quit())

        try:
            root.mainloop()
        except:
            master.quit()

        sys.exit()

    # ## if no tk and no password, ask for a password

    if not root and options.password == '<ask>':
        options.password = raw_input('choose a password:'******'no password, no admin interface'

    # ## start server

    (ip, port) = (options.ip, int(options.port))

    print 'please visit:'
    print '\thttp://%s:%s' % (ip, port)
    print 'use "kill -SIGTERM %i" to shutdown the web2py server' % os.getpid()

    server = HttpServer(ip=ip,
                        port=port,
                        password=options.password,
                        pid_filename=options.pid_filename,
                        log_filename=options.log_filename,
                        profiler_filename=options.profiler_filename,
                        ssl_certificate=options.ssl_certificate,
                        ssl_private_key=options.ssl_private_key,
                        numthreads=options.numthreads,
                        server_name=options.server_name,
                        request_queue_size=options.request_queue_size,
                        timeout=options.timeout,
                        shutdown_timeout=options.shutdown_timeout,
                        path=options.folder)

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
Example #4
0
class Web2pyService(Service):

    _svc_name_ = 'web2py'
    _svc_display_name_ = 'web2py Service'
    _exe_args_ = 'options'
    server = None

    def chdir(self):
        try:
            h = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
                                r'SYSTEM\CurrentControlSet\Services\%s'
                                 % self._svc_name_)
            cls = _winreg.QueryValue(h, 'PythonClass')
            dir = os.path.dirname(cls)
            os.chdir(dir)
            return True
        except:
            self.log("Can't change to web2py working path, server is stopped")
            return False

    def start(self):
        self.log('web2py server starting')
        if not self.chdir():
            return
        if len(sys.argv) == 2:
            opt_mod = sys.argv[1]
        else:
            opt_mod = self._exe_args_
        options = __import__(opt_mod, [], [], '')
        from main import HttpServer
        self.server = HttpServer(
            ip=options.ip,
            port=options.port,
            password=options.password,
            pid_filename=options.pid_filename,
            log_filename=options.log_filename,
            profiler_filename=options.profiler_filename,
            ssl_certificate=options.ssl_certificate,
            ssl_private_key=options.ssl_private_key,
            numthreads=options.numthreads,
            server_name=options.server_name,
            request_queue_size=options.request_queue_size,
            timeout=options.timeout,
            shutdown_timeout=options.shutdown_timeout,
            path=options.folder,
            )
        try:
            self.server.start()
        except:

            # self.server.stop()

            self.server = None
            raise

    def stop(self):
        self.log('web2py server stopping')
        if not self.chdir():
            return
        if self.server:
            self.server.stop()
        time.sleep(1)
def start(cron = True):
    """ Start server  """

    # ## get command line arguments

    (options, args) = console()

    print ProgramName
    print ProgramAuthor
    print ProgramVersion

    from sql import drivers
    print 'Database drivers available: %s' % ', '.join(drivers)


    # ## if -L load options from options.config file
    if options.config:
        try:
            options = __import__(options.config, [], [], '')
        except Exception:
            try:
                # Jython doesn't like the extra stuff
                options = __import__(options.config)
            except Exception:
                print 'Cannot import config file [%s]' % options.config
                sys.exit(1)


    # ## if -T run doctests (no cron)
    if options.test:
        test(options.test, verbose=options.verbose)
        return

    # ## if -S start interactive shell (also no cron)
    if options.shell:
        sys.args = options.args
        run(options.shell, plain=options.plain,
            import_models=options.import_models, startfile=options.run)
        return

    # ## if -C start cron run (extcron) and exit
    # ## if -N or not cron disable cron in this *process*
    # ## if --softcron use softcron
    # ## use hardcron in all ther cases
    if options.extcron:
        print 'Starting extcron...'
        settings.web2py_crontype = 'external'
        extcron = newcron.extcron(os.getcwd())
        extcron.start()
        extcron.join()
        return
    elif cron and not options.nocron and options.softcron:
        print 'Using softcron (but this is not very efficient)'
        settings.web2py_crontype = 'soft'
    elif cron and not options.nocron:
        print 'Starting hardcron...'
        settings.web2py_crontype = 'hard'
        newcron.hardcron(os.getcwd()).start()

    # ## if -W install/start/stop web2py as service
    if options.winservice:
        if os.name == 'nt':
            web2py_windows_service_handler(['', options.winservice],
                    options.config)
        else:
            print 'Error: Windows services not supported on this platform'
            sys.exit(1)
        return

    # ## if no password provided and havetk start Tk interface
    # ## or start interface if we want to put in taskbar (system tray)

    try:
        options.taskbar
    except:
        options.taskbar = False

    if options.taskbar and os.name != 'nt':
        print 'Error: taskbar not supported on this platform'
        sys.exit(1)

    root = None

    if not options.nogui:
        try:
            import tkMessageBox
            import Tkinter
            havetk = True
        except ImportError:
            logging.warn('GUI not available because Tk library is not installed')
            havetk = False

        if options.password == '<ask>' and havetk or options.taskbar and havetk:
            try:
                root = Tkinter.Tk()
            except:
                pass

    if root:
        root.focus_force()
        if not options.quiet:
            presentation(root)
        master = web2pyDialog(root, options)
        signal.signal(signal.SIGTERM, lambda a, b: master.quit())

        try:
            root.mainloop()
        except:
            master.quit()

        sys.exit()

    # ## if no tk and no password, ask for a password

    if not root and options.password == '<ask>':
        options.password = raw_input('choose a password:'******'no password, no admin interface'

    # ## start server

    (ip, port) = (options.ip, int(options.port))

    print 'please visit:'
    print '\thttp://%s:%s' % (ip, port)
    print 'use "kill -SIGTERM %i" to shutdown the web2py server' % os.getpid()

    server = HttpServer(ip=ip,
                        port=port,
                        password=options.password,
                        pid_filename=options.pid_filename,
                        log_filename=options.log_filename,
                        profiler_filename=options.profiler_filename,
                        ssl_certificate=options.ssl_certificate,
                        ssl_private_key=options.ssl_private_key,
                        numthreads=options.numthreads,
                        server_name=options.server_name,
                        request_queue_size=options.request_queue_size,
                        timeout=options.timeout,
                        shutdown_timeout=options.shutdown_timeout,
                        path=options.folder)

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
Example #6
0
def start(cron=True):
    """ Start server  """

    # ## get command line arguments

    (options, args) = console()

    print ProgramName
    print ProgramAuthor
    print ProgramVersion

    from sql import drivers

    print "Database drivers available: %s" % ", ".join(drivers)

    # ## Starts cron daemon

    if not options.shell and cron and not options.nocron:
        print "Starting cron..."
        contrib.cron.crontype = "hard"
        cron = contrib.cron.hardcron()
        cron.start()

    # ## if -W install/start/stop web2py as service

    if options.winservice:
        if os.name == "nt":
            web2py_windows_service_handler(["", options.winservice], options.config)
        else:
            print "Error: Windows services not supported on this platform"
            sys.exit(1)
        return

    # ## if -T run doctests

    if options.test:
        test(options.test, verbose=options.verbose)
        return

    # ## if -S start interactive shell

    if options.shell:
        sys.args = options.args
        run(options.shell, plain=options.plain, import_models=options.import_models, startfile=options.run)
        return

    # ## if -L load options from options.config file

    if options.config:
        try:
            options = __import__(options.config, [], [], "")
        except Exception:
            try:
                # Jython doesn't like the extra stuff
                options = __import__(options.config)
            except Exception:
                print "Cannot import config file [%s]" % options.config
                sys.exit(1)

    # ## if -C start cron run
    # ## if -N disable cron in this *process*
    # ##     - note, startup tasks WILL be run regardless !

    if options.extcron or options.nocron:
        contrib.cron.crontype = "External"
        if options.extcron:
            cron = contrib.cron.extcron()
            cron.start()
            cron.join()
            return

    # ## if no password provided and havetk start Tk interface
    # ## or start interface if we want to put in taskbar (system tray)

    try:
        options.taskbar
    except:
        options.taskbar = False

    if options.taskbar and os.name != "nt":
        print "Error: taskbar not supported on this platform"
        sys.exit(1)

    root = None

    if not options.nogui:
        try:
            import tkMessageBox
            import Tkinter

            havetk = True
        except ImportError:
            logging.warn("GUI not available because Tk library is not installed")
            havetk = False

        if options.password == "<ask>" and havetk or options.taskbar and havetk:
            try:
                root = Tkinter.Tk()
            except:
                pass

    if root:
        root.focus_force()
        if not options.quiet:
            presentation(root)
        master = web2pyDialog(root, options)
        signal.signal(signal.SIGTERM, lambda a, b: master.quit())

        try:
            root.mainloop()
        except:
            master.quit()

        sys.exit()

    # ## if no tk and no password, ask for a password

    if not root and options.password == "<ask>":
        options.password = raw_input("choose a password:"******"no password, no admin interface"

    # ## start server

    (ip, port) = (options.ip, int(options.port))

    print "please visit:"
    print "\thttp://%s:%s" % (ip, port)
    print 'use "kill -SIGTERM %i" to shutdown the web2py server' % os.getpid()

    server = HttpServer(
        ip=ip,
        port=port,
        password=options.password,
        pid_filename=options.pid_filename,
        log_filename=options.log_filename,
        profiler_filename=options.profiler_filename,
        ssl_certificate=options.ssl_certificate,
        ssl_private_key=options.ssl_private_key,
        numthreads=options.numthreads,
        server_name=options.server_name,
        request_queue_size=options.request_queue_size,
        timeout=options.timeout,
        shutdown_timeout=options.shutdown_timeout,
        path=options.folder,
    )

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
Example #7
0
class Web2pyService(Service):

    _svc_name_ = 'web2py'
    _svc_display_name_ = 'web2py Service'
    _exe_args_ = 'options'
    server = None

    def chdir(self):
        try:
            h = _winreg.OpenKey(
                _winreg.HKEY_LOCAL_MACHINE,
                r'SYSTEM\CurrentControlSet\Services\%s' % self._svc_name_)
            cls = _winreg.QueryValue(h, 'PythonClass')
            dir = os.path.dirname(cls)
            os.chdir(dir)
            return True
        except:
            self.log("Can't change to web2py working path, server is stopped")
            return False

    def start(self):
        self.log('web2py server starting')
        if not self.chdir():
            return
        if len(sys.argv) == 2:
            opt_mod = sys.argv[1]
        else:
            opt_mod = self._exe_args_
        options = __import__(opt_mod, [], [], '')
        from main import HttpServer
        self.server = HttpServer(
            ip=options.ip,
            port=options.port,
            password=options.password,
            pid_filename=options.pid_filename,
            log_filename=options.log_filename,
            profiler_filename=options.profiler_filename,
            ssl_certificate=options.ssl_certificate,
            ssl_private_key=options.ssl_private_key,
            numthreads=options.numthreads,
            server_name=options.server_name,
            request_queue_size=options.request_queue_size,
            timeout=options.timeout,
            shutdown_timeout=options.shutdown_timeout,
            path=options.folder,
        )
        try:
            self.server.start()
        except:

            # self.server.stop()

            self.server = None
            raise

    def stop(self):
        self.log('web2py server stopping')
        if not self.chdir():
            return
        if self.server:
            self.server.stop()
        time.sleep(1)