def serve(self): ''' start server listening on port, launch browser if requested & start the ioloop ''' self.http_server = httpserver.HTTPServer(self.app) self.http_server.listen(self.options.port) if not self.options.serveronly: launch_browser(self.options.port, self.options.browser) DEBUG('Serving on port %d' % self.options.port) try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: DEBUG('interrupt received, shutting down.')
def serve(self): ''' start server listening on port, launch browser if requested and start the ioloop ''' self.http_server = httpserver.HTTPServer(self.app) self.http_server.listen(self.options.port, address="localhost") if not self.options.serveronly: launch_browser(self.options.port, self.options.browser) DEBUG('Serving on port %d' % self.options.port) try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: DEBUG('interrupt received, shutting down.')
def serve(self): ''' Start server listening on port, launch browser if requested, and start the ioloop. ''' self.http_server = httpserver.HTTPServer(self.app) for retry in range(3): try: if self.options.external: self.http_server.listen(self.options.port) else: self.http_server.listen(self.options.port, address='localhost') except socket.error: # Possibly 'Address already in use', try finding another port. if self.options.orig_port < 1 and retry < 2: self.options.port = get_unused_ip_port() else: raise else: break if not self.options.serveronly: launch_browser(self.options.port, self.options.browser) if self.options.external: print '***********************************************************' print '** WARNING: You have exposed the server to the external **' print '** network. THIS IS NOT SAFE!! Clients will **' print '** have access to a command prompt on the host **' print '** computer with the identity and privileges of **' print '** the userid under which the server was run. **' print '** **' print '** This is very dangerous and you should NOT do it. **' print '** You exercise this option at your own risk!!! **' print '** (Ctrl-C to terminate server) **' print '***********************************************************' DEBUG('Serving on port %d' % self.options.port) try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: DEBUG('interrupt received, shutting down.')
help="preferred browser") parser.add_option("-s", "--server", action="store_true", dest="serveronly", help="don't launch browser, just run server") parser.add_option("-i", "--init", action="store_true", dest="initialize", help="(re)initialize settings") parser.add_option("-r", "--reset", action="store_true", dest="reset", help="reset project database (valid only with -i and without -d)") (options, args) = parser.parse_args() if options.initialize or not os.path.exists('settings.py'): if options.reset and not options.devserver: init(reset=True) else: init(reset=False) if (options.port < 1): options.port = get_unused_ip_port() if not options.serveronly: # NOTE: with dev server, you are going to get two browsers # this is due to forking I suppose # not sure what can be done about it launch_browser(options.port, options.browser) if (options.devserver): dev(options.port) else: pro(options.port)