Exemple #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()
Exemple #2
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()
Exemple #3
0
 def test_terminate_alien_true(self):
     _, pidfile = tempfile.mkstemp()
     child_pid = os.fork()
     if child_pid:
         time.sleep(0.1)
         with open(pidfile) as fp:
             pid = int(fp.read())
         self.assertTrue(is_running(pid))
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished-started, 1)
     else:
         doublefork(pidfile, '/dev/null', '.', 0)
         time.sleep(3)
         os._exit(os.EX_OK)
Exemple #4
0
 def test_terminate_alien_true(self):
     _, pidfile = tempfile.mkstemp()
     child_pid = os.fork()
     if child_pid:
         time.sleep(0.1)
         with open(pidfile) as fp:
             pid = int(fp.read())
         self.assertTrue(is_running(pid))
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished - started, 1)
     else:
         doublefork(pidfile, '/dev/null', '.', 0)
         time.sleep(3)
         os._exit(os.EX_OK)
Exemple #5
0
    def test_is_running_false(self):
        pid = os.fork()

        if pid:
            os.waitpid(pid, 0)
            self.assertFalse(is_running(pid))

        else:
            os._exit(0)
Exemple #6
0
    def test_is_running_false(self):
        pid = os.fork()

        if pid:
            os.waitpid(pid, 0)
            self.assertFalse(is_running(pid))

        else:
            os._exit(0)
Exemple #7
0
 def test_terminate_child_true(self):
     pid = os.fork()
     if pid:
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished - started, 1)
     else:
         time.sleep(3)
         os._exit(os.EX_OK)
Exemple #8
0
 def test_terminate_child_true(self):
     pid = os.fork()
     if pid:
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished-started, 1)
     else:
         time.sleep(3)
         os._exit(os.EX_OK)
Exemple #9
0
    def test_is_running_true(self):
        pid = os.fork()

        if pid:
            self.assertTrue(is_running(pid))

            # Cleaning up
            os.kill(pid, signal.SIGKILL)
            os.waitpid(pid, 0)

        else:
            time.sleep(1)
            os._exit(0)
Exemple #10
0
    def test_is_running_true(self):
        pid = os.fork()

        if pid:
            self.assertTrue(is_running(pid))

            # Cleaning up
            os.kill(pid, signal.SIGKILL)
            os.waitpid(pid, 0)

        else:
            time.sleep(1)
            os._exit(0)
Exemple #11
0
    def test_terminate_false(self):
        pid = os.fork()

        if pid:
            started = time.time()
            success = terminate(pid, 0, 0.5)
            finished = time.time()
            self.assertFalse(success)
            self.assertTrue(is_running(pid))
            self.assertLess(finished - started, 1)

            # Cleaning up
            os.kill(pid, signal.SIGKILL)
            os.waitpid(pid, 0)

        else:
            time.sleep(3)
            os._exit(os.EX_OK)
Exemple #12
0
    def test_terminate_false(self):
        pid = os.fork()

        if pid:
            started = time.time()
            success = terminate(pid, 0, 0.5)
            finished = time.time()
            self.assertFalse(success)
            self.assertTrue(is_running(pid))
            self.assertLess(finished-started, 1)

            # Cleaning up
            os.kill(pid, signal.SIGKILL)
            os.waitpid(pid, 0)

        else:
            time.sleep(3)
            os._exit(os.EX_OK)
Exemple #13
0
 def test_is_running_no_access(self):
     with self.assertRaises(OSError):
         is_running(1)
Exemple #14
0
 def test_is_running_no_access(self):
     with self.assertRaises(OSError):
         is_running(1)