diff --git a/minister/service/fastcgi.py b/minister/service/fastcgi.py index 977412c..0cbf4ea 100644 --- a/minister/service/fastcgi.py +++ b/minister/service/fastcgi.py @@ -17,7 +17,6 @@ class Service(base.Service): ### Instance Methods ################### def init(self): self._resource = FastCGI(address=self.address, filter=self.filter) - self.layout = Resource.create(self.layout) def _proxy(self, environ, start_response): self._resource(environ, start_response) \ No newline at end of file diff --git a/minister/service/php.py b/minister/service/php.py index e0ce479..a56b715 100644 --- a/minister/service/php.py +++ b/minister/service/php.py @@ -3,12 +3,12 @@ """ import os, sys -import fastcgi +import fastcgi, base from eventlet.green import socket from minister.static import Static -class Service(fastcgi.Service): +class Service(fastcgi.Service, base.ProcessService): type = 'php:service' address = ('127.0.0.1', 0) executable = 'php-cgi' @@ -16,6 +16,7 @@ class Service(fastcgi.Service): options = {} num_processes = 1 index = ('index.php', 'index.html') + port_range = (10000, 20000) def init(self): if (self.address[1] == 0): @@ -76,4 +77,20 @@ def find_index(self, path): candidate = os.path.join(path, i) if os.path.isfile(candidate): return candidate - return None \ No newline at end of file + return None + + _used_addresses = set() + def find_port(self): + host = self.address[0] + for port in range(*self.port_range): + if (host, port) in self._used_addresses: + continue + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + s.bind((host, port)) + except socket.error, e: + continue + else: + self._used_addresses.add((host, port)) + s.close() + return host, port \ No newline at end of file diff --git a/tests/test_functional.py b/tests/test_functional.py index 365d1f2..87f013c 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -18,7 +18,7 @@ def setUp(self): services = [{'type': 'admin', 'path': '@admin', 'url': 'admin/', 'site': '*'}] self.manager = Manager(path=self.repo_path, services=services, debug=True) eventlet.spawn(self.manager.serve, ('', port)) - eventlet.sleep(.03) #Give it some time to get on its feet. + eventlet.sleep(.3) #Give it some time to get on its feet. def tearDown(self): self.manager.close() @@ -50,5 +50,5 @@ def test_b(self): self.assertEqual(request.status, 404) def test_d(self): - self.assertEqual(self.manager.get_service('d').status, 'mia') + self.assertEqual(self.manager.get_service('d').status, 'failed') \ No newline at end of file