OLD | NEW |
1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 21 matching lines...) Expand all Loading... |
32 import os | 32 import os |
33 import socket | 33 import socket |
34 | 34 |
35 from webkitpy.layout_tests.servers import server_base | 35 from webkitpy.layout_tests.servers import server_base |
36 | 36 |
37 | 37 |
38 _log = logging.getLogger(__name__) | 38 _log = logging.getLogger(__name__) |
39 | 39 |
40 | 40 |
41 class ApacheHTTP(server_base.ServerBase): | 41 class ApacheHTTP(server_base.ServerBase): |
| 42 |
42 def __init__(self, port_obj, output_dir, additional_dirs, number_of_servers)
: | 43 def __init__(self, port_obj, output_dir, additional_dirs, number_of_servers)
: |
43 super(ApacheHTTP, self).__init__(port_obj, output_dir) | 44 super(ApacheHTTP, self).__init__(port_obj, output_dir) |
44 # We use the name "httpd" instead of "apache" to make our paths (e.g. th
e pid file: /tmp/WebKit/httpd.pid) | 45 # We use the name "httpd" instead of "apache" to make our paths (e.g. th
e pid file: /tmp/WebKit/httpd.pid) |
45 # match old-run-webkit-tests: https://bugs.webkit.org/show_bug.cgi?id=63
956 | 46 # match old-run-webkit-tests: https://bugs.webkit.org/show_bug.cgi?id=63
956 |
46 self._name = 'httpd' | 47 self._name = 'httpd' |
47 self._log_prefixes = ('access_log', 'error_log') | 48 self._log_prefixes = ('access_log', 'error_log') |
48 self._mappings = [{'port': 8000}, | 49 self._mappings = [{'port': 8000}, |
49 {'port': 8080}, | 50 {'port': 8080}, |
50 {'port': 8443, 'sslcert': True}] | 51 {'port': 8443, 'sslcert': True}] |
51 self._number_of_servers = number_of_servers | 52 self._number_of_servers = number_of_servers |
52 | 53 |
53 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se
lf._name) | 54 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se
lf._name) |
54 | 55 |
55 executable = self._port_obj.path_to_apache() | 56 executable = self._port_obj.path_to_apache() |
56 server_root = self._filesystem.dirname(self._filesystem.dirname(executab
le)) | 57 server_root = self._filesystem.dirname(self._filesystem.dirname(executab
le)) |
57 | 58 |
58 test_dir = self._port_obj.layout_tests_dir() | 59 test_dir = self._port_obj.layout_tests_dir() |
59 document_root = self._filesystem.join(test_dir, "http", "tests") | 60 document_root = self._filesystem.join(test_dir, 'http', 'tests') |
60 js_test_resources_dir = self._filesystem.join(test_dir, "resources") | 61 js_test_resources_dir = self._filesystem.join(test_dir, 'resources') |
61 media_resources_dir = self._filesystem.join(test_dir, "media") | 62 media_resources_dir = self._filesystem.join(test_dir, 'media') |
62 mime_types_path = self._filesystem.join(test_dir, "http", "conf", "mime.
types") | 63 mime_types_path = self._filesystem.join(test_dir, 'http', 'conf', 'mime.
types') |
63 cert_file = self._filesystem.join(test_dir, "http", "conf", "webkit-http
d.pem") | 64 cert_file = self._filesystem.join(test_dir, 'http', 'conf', 'webkit-http
d.pem') |
64 | 65 |
65 self._access_log_path = self._filesystem.join(output_dir, "access_log.tx
t") | 66 self._access_log_path = self._filesystem.join(output_dir, 'access_log.tx
t') |
66 self._error_log_path = self._filesystem.join(output_dir, "error_log.txt"
) | 67 self._error_log_path = self._filesystem.join(output_dir, 'error_log.txt'
) |
67 | 68 |
68 self._is_win = self._port_obj.host.platform.is_win() | 69 self._is_win = self._port_obj.host.platform.is_win() |
69 | 70 |
70 start_cmd = [executable, | 71 start_cmd = [executable, |
71 '-f', '%s' % self._port_obj.path_to_apache_config_file(), | 72 '-f', '%s' % self._port_obj.path_to_apache_config_file(), |
72 '-C', 'ServerRoot "%s"' % server_root, | 73 '-C', 'ServerRoot "%s"' % server_root, |
73 '-C', 'DocumentRoot "%s"' % document_root, | 74 '-C', 'DocumentRoot "%s"' % document_root, |
74 '-c', 'Alias /js-test-resources "%s"' % js_test_resources_dir, | 75 '-c', 'Alias /js-test-resources "%s"' % js_test_resources_d
ir, |
75 '-c', 'Alias /media-resources "%s"' % media_resources_dir, | 76 '-c', 'Alias /media-resources "%s"' % media_resources_dir, |
76 '-c', 'TypesConfig "%s"' % mime_types_path, | 77 '-c', 'TypesConfig "%s"' % mime_types_path, |
77 '-c', 'CustomLog "%s" common' % self._access_log_path, | 78 '-c', 'CustomLog "%s" common' % self._access_log_path, |
78 '-c', 'ErrorLog "%s"' % self._error_log_path, | 79 '-c', 'ErrorLog "%s"' % self._error_log_path, |
79 '-c', 'PidFile %s' % self._pid_file, | 80 '-c', 'PidFile %s' % self._pid_file, |
80 '-c', 'SSLCertificateFile "%s"' % cert_file, | 81 '-c', 'SSLCertificateFile "%s"' % cert_file, |
81 ] | 82 ] |
82 | 83 |
83 if self._is_win: | 84 if self._is_win: |
84 start_cmd += ['-c', "ThreadsPerChild %d" % (self._number_of_servers
* 2)] | 85 start_cmd += ['-c', 'ThreadsPerChild %d' % (self._number_of_servers
* 2)] |
85 else: | 86 else: |
86 start_cmd += ['-c', "StartServers %d" % self._number_of_servers, | 87 start_cmd += ['-c', 'StartServers %d' % self._number_of_servers, |
87 '-c', "MinSpareServers %d" % self._number_of_servers, | 88 '-c', 'MinSpareServers %d' % self._number_of_servers, |
88 '-c', "MaxSpareServers %d" % self._number_of_servers, | 89 '-c', 'MaxSpareServers %d' % self._number_of_servers, |
89 '-C', 'User "%s"' % os.environ.get('USERNAME', os.envi
ron.get('USER', '')), | 90 '-C', 'User "%s"' % os.environ.get('USERNAME', os.envi
ron.get('USER', '')), |
90 '-k', 'start'] | 91 '-k', 'start'] |
91 | 92 |
92 enable_ipv6 = self._port_obj.http_server_supports_ipv6() | 93 enable_ipv6 = self._port_obj.http_server_supports_ipv6() |
93 # Perform part of the checks Apache's APR does when trying to listen to | 94 # Perform part of the checks Apache's APR does when trying to listen to |
94 # a specific host/port. This allows us to avoid trying to listen to | 95 # a specific host/port. This allows us to avoid trying to listen to |
95 # IPV6 addresses when it fails on Apache. APR itself tries to call | 96 # IPV6 addresses when it fails on Apache. APR itself tries to call |
96 # getaddrinfo() again without AI_ADDRCONFIG if the first call fails | 97 # getaddrinfo() again without AI_ADDRCONFIG if the first call fails |
97 # with EBADFLAGS, but that is not how it normally fails in our use | 98 # with EBADFLAGS, but that is not how it normally fails in our use |
98 # cases, so ignore that for now. | 99 # cases, so ignore that for now. |
99 # See https://bugs.webkit.org/show_bug.cgi?id=98602#c7 | 100 # See https://bugs.webkit.org/show_bug.cgi?id=98602#c7 |
100 try: | 101 try: |
101 socket.getaddrinfo('::1', 0, 0, 0, 0, socket.AI_ADDRCONFIG) | 102 socket.getaddrinfo('::1', 0, 0, 0, 0, socket.AI_ADDRCONFIG) |
102 except: | 103 except: |
103 enable_ipv6 = False | 104 enable_ipv6 = False |
104 | 105 |
105 for mapping in self._mappings: | 106 for mapping in self._mappings: |
106 port = mapping['port'] | 107 port = mapping['port'] |
107 | 108 |
108 start_cmd += ['-C', "Listen 127.0.0.1:%d" % port] | 109 start_cmd += ['-C', 'Listen 127.0.0.1:%d' % port] |
109 | 110 |
110 # We listen to both IPv4 and IPv6 loop-back addresses, but ignore | 111 # We listen to both IPv4 and IPv6 loop-back addresses, but ignore |
111 # requests to 8000 from random users on network. | 112 # requests to 8000 from random users on network. |
112 # See https://bugs.webkit.org/show_bug.cgi?id=37104 | 113 # See https://bugs.webkit.org/show_bug.cgi?id=37104 |
113 if enable_ipv6: | 114 if enable_ipv6: |
114 start_cmd += ['-C', "Listen [::1]:%d" % port] | 115 start_cmd += ['-C', 'Listen [::1]:%d' % port] |
115 | 116 |
116 if additional_dirs: | 117 if additional_dirs: |
117 self._start_cmd = start_cmd | 118 self._start_cmd = start_cmd |
118 for alias, path in additional_dirs.iteritems(): | 119 for alias, path in additional_dirs.iteritems(): |
119 start_cmd += ['-c', 'Alias %s "%s"' % (alias, path), | 120 start_cmd += ['-c', 'Alias %s "%s"' % (alias, path), |
120 # Disable CGI handler for additional dirs. | 121 # Disable CGI handler for additional dirs. |
121 '-c', '<Location %s>' % alias, | 122 '-c', '<Location %s>' % alias, |
122 '-c', 'RemoveHandler .cgi .pl', | 123 '-c', 'RemoveHandler .cgi .pl', |
123 '-c', '</Location>'] | 124 '-c', '</Location>'] |
124 | 125 |
125 self._start_cmd = start_cmd | 126 self._start_cmd = start_cmd |
126 | 127 |
127 def _spawn_process(self): | 128 def _spawn_process(self): |
128 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start
_cmd))) | 129 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start
_cmd))) |
129 self._process = self._executive.popen(self._start_cmd, stderr=self._exec
utive.PIPE) | 130 self._process = self._executive.popen(self._start_cmd, stderr=self._exec
utive.PIPE) |
130 if self._process.returncode is not None: | 131 if self._process.returncode is not None: |
131 retval = self._process.returncode | 132 retval = self._process.returncode |
132 err = self._process.stderr.read() | 133 err = self._process.stderr.read() |
133 if retval or len(err): | 134 if retval or len(err): |
(...skipping 29 matching lines...) Expand all Loading... |
163 retval = proc.returncode | 164 retval = proc.returncode |
164 err = proc.stderr.read() | 165 err = proc.stderr.read() |
165 if retval or len(err): | 166 if retval or len(err): |
166 raise server_base.ServerError('Failed to stop %s: %s' % (self._name,
err)) | 167 raise server_base.ServerError('Failed to stop %s: %s' % (self._name,
err)) |
167 | 168 |
168 # For some reason apache isn't guaranteed to have actually stopped after | 169 # For some reason apache isn't guaranteed to have actually stopped after |
169 # the stop command returns, so we wait a little while longer for the | 170 # the stop command returns, so we wait a little while longer for the |
170 # pid file to be removed. | 171 # pid file to be removed. |
171 if not self._wait_for_action(lambda: not self._filesystem.exists(self._p
id_file)): | 172 if not self._wait_for_action(lambda: not self._filesystem.exists(self._p
id_file)): |
172 raise server_base.ServerError('Failed to stop %s: pid file still exi
sts' % self._name) | 173 raise server_base.ServerError('Failed to stop %s: pid file still exi
sts' % self._name) |
OLD | NEW |