def main():
<EOL>tornado.options.parse_command_line()<EOL>DEBUG = True if options.debugmode == <NUM_LIT:1> else False<EOL>LOGGER = logging.getLogger('<STR_LIT>')<EOL>if DEBUG:<EOL><INDENT>LOGGER.setLevel(logging.DEBUG)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.setLevel(logging.INFO)<EOL><DEDENT>MAXPROCS = options.maxprocs<EOL>ASSETPATH = options.assetpath<EOL>BASEURL = options.baseurl<EOL>EXECUTOR = ProcessPoolExecutor(MAXPROCS)<EOL>if options.standalone:<EOL><INDENT>if ( (not options.sharedsecret) or<EOL>(options.sharedsecret and<EOL>not os.path.exists(options.sharedsecret)) ):<EOL><INDENT>LOGGER.error('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>elif options.sharedsecret and os.path.exists(options.sharedsecret):<EOL><INDENT>fileperm = oct(os.stat(options.sharedsecret)[stat.ST_MODE])<EOL>if fileperm == '<STR_LIT>' or fileperm == '<STR_LIT>':<EOL><INDENT>with open(options.sharedsecret,'<STR_LIT:r>') as infd:<EOL><INDENT>SHAREDSECRET = infd.read().strip('<STR_LIT:\n>')<EOL>standalonespec = (<EOL>r'<STR_LIT>',<EOL>cphandlers.StandaloneHandler,<EOL>{'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':SHAREDSECRET}<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.error('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>options.sharedsecret)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>HANDLERS = [standalonespec]<EOL><DEDENT>else:<EOL><INDENT>if not BASEURL.endswith('<STR_LIT:/>'):<EOL><INDENT>BASEURL = BASEURL + '<STR_LIT:/>'<EOL><DEDENT>READONLY = options.readonly<EOL>if READONLY:<EOL><INDENT>LOGGER.warning('<STR_LIT>')<EOL><DEDENT>CURRENTDIR = os.getcwd()<EOL>cplistfile = options.checkplotlist<EOL>if cplistfile and os.path.exists(cplistfile):<EOL><INDENT>with open(cplistfile,'<STR_LIT:r>') as infd:<EOL><INDENT>CHECKPLOTLIST = json.load(infd)<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cplistfile)<EOL><DEDENT>elif cplistfile and not os.path.exists(cplistfile):<EOL><INDENT>helpmsg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>(cplistfile, os.path.join(modpath,'<STR_LIT>'))<EOL>)<EOL>LOGGER.error(helpmsg)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>LOGGER.warning('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % CURRENTDIR)<EOL>if os.path.exists(<EOL>os.path.join(CURRENTDIR,'<STR_LIT>')<EOL>):<EOL><INDENT>cplistfile = os.path.join(CURRENTDIR,'<STR_LIT>')<EOL>with open(cplistfile,'<STR_LIT:r>') as infd:<EOL><INDENT>CHECKPLOTLIST = json.load(infd)<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cplistfile)<EOL><DEDENT>elif os.path.exists(os.path.join(CURRENTDIR,<EOL>'<STR_LIT>')):<EOL><INDENT>cplistfile = os.path.join(CURRENTDIR,<EOL>'<STR_LIT>')<EOL>with open(cplistfile,'<STR_LIT:r>') as infd:<EOL><INDENT>CHECKPLOTLIST = json.load(infd)<EOL><DEDENT>LOGGER.info('<STR_LIT>' % cplistfile)<EOL><DEDENT>else:<EOL><INDENT>helpmsg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>LOGGER.error(helpmsg)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>HANDLERS = [<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.IndexHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY,<EOL>'<STR_LIT>':BASEURL}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.CheckplotHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.CheckplotListHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>cphandlers.LCToolHandler,<EOL>{'<STR_LIT>':CURRENTDIR,<EOL>'<STR_LIT>':ASSETPATH,<EOL>'<STR_LIT>':CHECKPLOTLIST,<EOL>'<STR_LIT>':cplistfile,<EOL>'<STR_LIT>':EXECUTOR,<EOL>'<STR_LIT>':READONLY}),<EOL>(r'<STR_LIT>'.format(baseurl=BASEURL),<EOL>tornado.web.StaticFileHandler, {'<STR_LIT:path>': CURRENTDIR})<EOL>]<EOL><DEDENT>app = tornado.web.Application(<EOL>handlers=HANDLERS,<EOL>static_path=ASSETPATH,<EOL>template_path=ASSETPATH,<EOL>static_url_prefix='<STR_LIT>'.format(baseurl=BASEURL),<EOL>compress_response=True,<EOL>debug=DEBUG,<EOL>)<EOL>http_server = tornado.httpserver.HTTPServer(app, xheaders=True)<EOL>portok = False<EOL>serverport = options.port<EOL>maxtrys = <NUM_LIT:5><EOL>thistry = <NUM_LIT:0><EOL>while not portok and thistry < maxtrys:<EOL><INDENT>try:<EOL><INDENT>http_server.listen(serverport, options.serve)<EOL>portok = True<EOL><DEDENT>except socket.error as e:<EOL><INDENT>LOGGER.warning('<STR_LIT>' %<EOL>(options.serve, serverport, serverport + <NUM_LIT:1>))<EOL>serverport = serverport + <NUM_LIT:1><EOL><DEDENT><DEDENT>if not portok:<EOL><INDENT>LOGGER.error('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>LOGGER.info('<STR_LIT>' %<EOL>(options.serve, serverport, BASEURL))<EOL>signal.signal(signal.SIGINT,_recv_sigint)<EOL>signal.signal(signal.SIGTERM,_recv_sigint)<EOL>try:<EOL><INDENT>tornado.ioloop.IOLoop.instance().start()<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>LOGGER.info('<STR_LIT>')<EOL>tornado.ioloop.IOLoop.instance().stop()<EOL><DEDENT>EXECUTOR.shutdown()<EOL>time.sleep(<NUM_LIT:3>)<EOL>
This launches the server. The current script args are shown below::

  Usage: checkplotserver [OPTIONS]

  Options:

    --help                           show this help information

  checkplotserver.py options:

    --assetpath                      Sets the asset (server images, css, js, DB)
                                     path for checkplotserver.
                                     (default <astrobase install dir>
                                      /astrobase/cpserver/cps-assets)
    --baseurl                        Set the base URL of the checkplotserver.
                                     This is useful when you're running
                                     checkplotserver on a remote machine and are
                                     reverse-proxying more than one instances of
                                     it so you can access them using HTTP from
                                     outside on different base URLs like
                                     /cpserver1/, /cpserver2/, etc. If this is
                                     set, all URLs will take the form
                                     [baseurl]/..., instead of /... (default /)
    --checkplotlist                  The path to the checkplot-filelist.json file
                                     listing checkplots to load and serve. If
                                     this is not provided, checkplotserver will
                                     look for a checkplot-pickle-flist.json in
                                     the directory that it was started in
    --debugmode                      start up in debug mode if set to 1. (default
                                     0)
    --maxprocs                       Number of background processes to use for
                                     saving/loading checkplot files and running
                                     light curves tools (default 2)
    --port                           Run on the given port. (default 5225)
    --readonly                       Run the server in readonly mode. This is
                                     useful for a public-facing instance of
                                     checkplotserver where you just want to allow
                                     collaborators to review objects but not edit
                                     them. (default False)
    --serve                          Bind to given address and serve content.
                                     (default 127.0.0.1)
    --sharedsecret                   a file containing a cryptographically secure
                                     string that is used to authenticate requests
                                     that come into the special standalone mode.
    --standalone                     This starts the server in standalone mode.
                                     (default 0)

  tornado/log.py options:

    --log-file-max-size              max size of log files before rollover
                                     (default 100000000)
    --log-file-num-backups           number of log files to keep (default 10)
    --log-file-prefix=PATH           Path prefix for log files. Note that if you
                                     are running multiple tornado processes,
                                     log_file_prefix must be different for each
                                     of them (e.g. include the port number)
    --log-rotate-interval            The interval value of timed rotating
                                     (default 1)
    --log-rotate-mode                The mode of rotating files(time or size)
                                     (default size)
    --log-rotate-when                specify the type of TimedRotatingFileHandler
                                     interval other options:('S', 'M', 'H', 'D',
                                     'W0'-'W6') (default midnight)
    --log-to-stderr                  Send log output to stderr (colorized if
                                     possible). By default use stderr if
                                     --log_file_prefix is not set and no other
                                     logging is configured.
    --logging=debug|info|warning|error|none
                                     Set the Python log level. If 'none', tornado
                                     won't touch the logging configuration.
                                     (default info)