Esempio n. 1
0
def flup_fastcgi(wsgi_app,
                 bind,
                 cwd=None,
                 pidfile=None,
                 logfile=None,
                 daemonize=False,
                 umask=None,
                 **params):
    if params.pop('preforked', False):
        from flup.server import fcgi_fork as fcgi
    else:
        from flup.server import fcgi
    if daemonize:
        if os.path.isfile(pidfile):
            with open(pidfile, 'r') as f:
                try:
                    pid = int(f.read())
                except ValueError:
                    pid = None

            if pid is not None and is_running(pid):
                sys.exit('Already running (PID: {})'.format(pid))
            elif pid is not None:
                logger.info('PID file was pointing to nonexistent process %r',
                            pid)
            else:
                logger.info('PID file should contain a number')
        doublefork(pidfile, logfile, cwd, umask)
    logger.info('Starting FastCGI server (flup), current working dir %r', cwd)
    fcgi.WSGIServer(wsgi_app,
                    bindAddress=bind,
                    umask=umask,
                    debug=False,
                    **params).run()
Esempio n. 2
0
def runfcgi(func, addr=('localhost', 8000)):
    """Runs a WSGI function as a FastCGI pre-fork server."""
    config = dict(web.config.get("fastcgi", {}))

    mode = config.pop("mode", None)
    if mode == "prefork":
        import flup.server.fcgi_fork as flups
    else:
        import flup.server.fcgi as flups

    return flups.WSGIServer(func, multiplexed=True, bindAddress=addr, **config).run()
Esempio n. 3
0
        from flup.server import fcgi_fork as fcgi
    else:
        from flup.server import fcgi
    cur_dir = cur_dir or path.abspath('.')
    run_dir = path.join(cur_dir, 'run')
    pidfile = pidfile or path.join(run_dir, 'fcgi.pid')
    prepare_dir(pidfile)
    logfile = logfile or path.join(run_dir, 'fcgi.log')
    prepare_dir(logfile)
    if ':' in bind:
        host, port = bind.split(':')
        port = int(port)
    else:
        bind = bind or path.join(run_dir, 'fcgi.sock')
        prepare_dir(bind)
    if daemon:
        if path.isfile(pidfile):
            fp = open(pidfile, 'r')
            pid = int(fp.read())
            fp.close()
            try:
                os.kill(pid, 0)
                print 'process allready running'
                sys.exit(1)
            except OSError, err:
                logger.info('Process allready running: (%d) %s\n' % \
                        (err.errno, err.strerror))
        doublefork(pidfile, logfile, cur_dir)
    logger.info("Starting FastCGI server (flup), current dir '%s'" % cur_dir)
    fcgi.WSGIServer(wsgi_app, bindAddress=bind, umask=777, debug=False).run()