| 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 |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
| 29 """Start and stop the Apache HTTP server as it is used by the layout tests.""" | 28 """Start and stop the Apache HTTP server as it is used by the layout tests.""" |
| 30 | 29 |
| 31 import logging | 30 import logging |
| 32 import os | 31 import os |
| 33 import socket | 32 import socket |
| 34 | 33 |
| 35 from webkitpy.layout_tests.servers import server_base | 34 from webkitpy.layout_tests.servers import server_base |
| 36 | 35 |
| 37 | |
| 38 _log = logging.getLogger(__name__) | 36 _log = logging.getLogger(__name__) |
| 39 | 37 |
| 40 | 38 |
| 41 class ApacheHTTP(server_base.ServerBase): | 39 class ApacheHTTP(server_base.ServerBase): |
| 42 def __init__(self, port_obj, output_dir, additional_dirs, number_of_servers)
: | 40 def __init__(self, port_obj, output_dir, additional_dirs, number_of_servers)
: |
| 43 super(ApacheHTTP, self).__init__(port_obj, output_dir) | 41 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) | 42 # 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 | 43 # match old-run-webkit-tests: https://bugs.webkit.org/show_bug.cgi?id=63
956 |
| 46 self._name = 'httpd' | 44 self._name = 'httpd' |
| 47 self._log_prefixes = ('access_log', 'error_log') | 45 self._log_prefixes = ('access_log', 'error_log') |
| 48 self._mappings = [{'port': 8000}, | 46 self._mappings = [{'port': 8000}, {'port': 8080}, {'port': 8443, 'sslcer
t': True}] |
| 49 {'port': 8080}, | |
| 50 {'port': 8443, 'sslcert': True}] | |
| 51 self._number_of_servers = number_of_servers | 47 self._number_of_servers = number_of_servers |
| 52 | 48 |
| 53 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se
lf._name) | 49 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se
lf._name) |
| 54 | 50 |
| 55 executable = self._port_obj.path_to_apache() | 51 executable = self._port_obj.path_to_apache() |
| 56 server_root = self._filesystem.dirname(self._filesystem.dirname(executab
le)) | 52 server_root = self._filesystem.dirname(self._filesystem.dirname(executab
le)) |
| 57 | 53 |
| 58 test_dir = self._port_obj.layout_tests_dir() | 54 test_dir = self._port_obj.layout_tests_dir() |
| 59 document_root = self._filesystem.join(test_dir, "http", "tests") | 55 document_root = self._filesystem.join(test_dir, "http", "tests") |
| 60 js_test_resources_dir = self._filesystem.join(test_dir, "resources") | 56 js_test_resources_dir = self._filesystem.join(test_dir, "resources") |
| 61 forms_test_resources_dir = self._filesystem.join(test_dir, "fast", "form
s", "resources") | 57 forms_test_resources_dir = self._filesystem.join(test_dir, "fast", "form
s", "resources") |
| 62 media_resources_dir = self._filesystem.join(test_dir, "media") | 58 media_resources_dir = self._filesystem.join(test_dir, "media") |
| 63 mime_types_path = self._filesystem.join(test_dir, "http", "conf", "mime.
types") | 59 mime_types_path = self._filesystem.join(test_dir, "http", "conf", "mime.
types") |
| 64 cert_file = self._filesystem.join(test_dir, "http", "conf", "webkit-http
d.pem") | 60 cert_file = self._filesystem.join(test_dir, "http", "conf", "webkit-http
d.pem") |
| 65 inspector_sources_dir = self._port_obj.inspector_build_directory() | 61 inspector_sources_dir = self._port_obj.inspector_build_directory() |
| 66 | 62 |
| 67 self._access_log_path = self._filesystem.join(output_dir, "access_log.tx
t") | 63 self._access_log_path = self._filesystem.join(output_dir, "access_log.tx
t") |
| 68 self._error_log_path = self._filesystem.join(output_dir, "error_log.txt"
) | 64 self._error_log_path = self._filesystem.join(output_dir, "error_log.txt"
) |
| 69 | 65 |
| 70 self._is_win = self._port_obj.host.platform.is_win() | 66 self._is_win = self._port_obj.host.platform.is_win() |
| 71 | 67 |
| 72 start_cmd = [ | 68 start_cmd = [ |
| 73 executable, | 69 executable, |
| 74 '-f', '%s' % self._port_obj.path_to_apache_config_file(), | 70 '-f', |
| 75 '-C', 'ServerRoot "%s"' % server_root, | 71 '%s' % self._port_obj.path_to_apache_config_file(), |
| 76 '-C', 'DocumentRoot "%s"' % document_root, | 72 '-C', |
| 77 '-c', 'Alias /js-test-resources "%s"' % js_test_resources_dir, | 73 'ServerRoot "%s"' % server_root, |
| 78 '-c', 'Alias /forms-test-resources "%s"' % forms_test_resources_dir, | 74 '-C', |
| 79 '-c', 'Alias /media-resources "%s"' % media_resources_dir, | 75 'DocumentRoot "%s"' % document_root, |
| 80 '-c', 'TypesConfig "%s"' % mime_types_path, | 76 '-c', |
| 81 '-c', 'CustomLog "%s" common' % self._access_log_path, | 77 'Alias /js-test-resources "%s"' % js_test_resources_dir, |
| 82 '-c', 'ErrorLog "%s"' % self._error_log_path, | 78 '-c', |
| 83 '-c', 'PidFile %s' % self._pid_file, | 79 'Alias /forms-test-resources "%s"' % forms_test_resources_dir, |
| 84 '-c', 'SSLCertificateFile "%s"' % cert_file, | 80 '-c', |
| 85 '-c', 'Alias /inspector-sources "%s"' % inspector_sources_dir, | 81 'Alias /media-resources "%s"' % media_resources_dir, |
| 86 ] | 82 '-c', |
| 83 'TypesConfig "%s"' % mime_types_path, |
| 84 '-c', |
| 85 'CustomLog "%s" common' % self._access_log_path, |
| 86 '-c', |
| 87 'ErrorLog "%s"' % self._error_log_path, |
| 88 '-c', |
| 89 'PidFile %s' % self._pid_file, |
| 90 '-c', |
| 91 'SSLCertificateFile "%s"' % cert_file, |
| 92 '-c', |
| 93 'Alias /inspector-sources "%s"' % inspector_sources_dir, |
| 94 ] |
| 87 | 95 |
| 88 if self._is_win: | 96 if self._is_win: |
| 89 start_cmd += ['-c', "ThreadsPerChild %d" % (self._number_of_servers
* 8)] | 97 start_cmd += ['-c', "ThreadsPerChild %d" % (self._number_of_servers
* 8)] |
| 90 else: | 98 else: |
| 91 start_cmd += ['-c', "StartServers %d" % self._number_of_servers, | 99 start_cmd += ['-c', "StartServers %d" % self._number_of_servers, '-c
', "MinSpareServers %d" % self._number_of_servers, |
| 92 '-c', "MinSpareServers %d" % self._number_of_servers, | 100 '-c', "MaxSpareServers %d" % self._number_of_servers,
'-C', |
| 93 '-c', "MaxSpareServers %d" % self._number_of_servers, | 101 'User "%s"' % os.environ.get('USERNAME', os.environ.ge
t('USER', '')), '-k', 'start'] |
| 94 '-C', 'User "%s"' % os.environ.get('USERNAME', os.envi
ron.get('USER', '')), | |
| 95 '-k', 'start'] | |
| 96 | 102 |
| 97 enable_ipv6 = self._port_obj.http_server_supports_ipv6() | 103 enable_ipv6 = self._port_obj.http_server_supports_ipv6() |
| 98 # Perform part of the checks Apache's APR does when trying to listen to | 104 # Perform part of the checks Apache's APR does when trying to listen to |
| 99 # a specific host/port. This allows us to avoid trying to listen to | 105 # a specific host/port. This allows us to avoid trying to listen to |
| 100 # IPV6 addresses when it fails on Apache. APR itself tries to call | 106 # IPV6 addresses when it fails on Apache. APR itself tries to call |
| 101 # getaddrinfo() again without AI_ADDRCONFIG if the first call fails | 107 # getaddrinfo() again without AI_ADDRCONFIG if the first call fails |
| 102 # with EBADFLAGS, but that is not how it normally fails in our use | 108 # with EBADFLAGS, but that is not how it normally fails in our use |
| 103 # cases, so ignore that for now. | 109 # cases, so ignore that for now. |
| 104 # See https://bugs.webkit.org/show_bug.cgi?id=98602#c7 | 110 # See https://bugs.webkit.org/show_bug.cgi?id=98602#c7 |
| 105 try: | 111 try: |
| 106 socket.getaddrinfo('::1', 0, 0, 0, 0, socket.AI_ADDRCONFIG) | 112 socket.getaddrinfo('::1', 0, 0, 0, 0, socket.AI_ADDRCONFIG) |
| 107 except: | 113 except: |
| 108 enable_ipv6 = False | 114 enable_ipv6 = False |
| 109 | 115 |
| 110 for mapping in self._mappings: | 116 for mapping in self._mappings: |
| 111 port = mapping['port'] | 117 port = mapping['port'] |
| 112 | 118 |
| 113 start_cmd += ['-C', "Listen 127.0.0.1:%d" % port] | 119 start_cmd += ['-C', "Listen 127.0.0.1:%d" % port] |
| 114 | 120 |
| 115 # We listen to both IPv4 and IPv6 loop-back addresses, but ignore | 121 # We listen to both IPv4 and IPv6 loop-back addresses, but ignore |
| 116 # requests to 8000 from random users on network. | 122 # requests to 8000 from random users on network. |
| 117 # See https://bugs.webkit.org/show_bug.cgi?id=37104 | 123 # See https://bugs.webkit.org/show_bug.cgi?id=37104 |
| 118 if enable_ipv6: | 124 if enable_ipv6: |
| 119 start_cmd += ['-C', "Listen [::1]:%d" % port] | 125 start_cmd += ['-C', "Listen [::1]:%d" % port] |
| 120 | 126 |
| 121 if additional_dirs: | 127 if additional_dirs: |
| 122 self._start_cmd = start_cmd | 128 self._start_cmd = start_cmd |
| 123 for alias, path in additional_dirs.iteritems(): | 129 for alias, path in additional_dirs.iteritems(): |
| 124 start_cmd += ['-c', 'Alias %s "%s"' % (alias, path), | 130 start_cmd += ['-c', |
| 125 # Disable CGI handler for additional dirs. | 131 'Alias %s "%s"' % (alias, path), |
| 126 '-c', '<Location %s>' % alias, | 132 # Disable CGI handler for additional dirs. |
| 127 '-c', 'RemoveHandler .cgi .pl', | 133 '-c', |
| 128 '-c', '</Location>'] | 134 '<Location %s>' % alias, |
| 135 '-c', |
| 136 'RemoveHandler .cgi .pl', |
| 137 '-c', |
| 138 '</Location>'] |
| 129 | 139 |
| 130 self._start_cmd = start_cmd | 140 self._start_cmd = start_cmd |
| 131 | 141 |
| 132 def _spawn_process(self): | 142 def _spawn_process(self): |
| 133 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start
_cmd))) | 143 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start
_cmd))) |
| 134 self._process = self._executive.popen(self._start_cmd) | 144 self._process = self._executive.popen(self._start_cmd) |
| 135 retval = self._process.returncode | 145 retval = self._process.returncode |
| 136 if retval: | 146 if retval: |
| 137 raise server_base.ServerError('Failed to start %s: %s' % (self._name
, retval)) | 147 raise server_base.ServerError('Failed to start %s: %s' % (self._name
, retval)) |
| 138 | 148 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 151 # If apache was forcefully killed, the pid file will not have been delet
ed, so check | 161 # If apache was forcefully killed, the pid file will not have been delet
ed, so check |
| 152 # that the process specified by the pid_file no longer exists before del
eting the file. | 162 # that the process specified by the pid_file no longer exists before del
eting the file. |
| 153 if self._pid and not self._executive.check_running_pid(self._pid): | 163 if self._pid and not self._executive.check_running_pid(self._pid): |
| 154 self._filesystem.remove(self._pid_file) | 164 self._filesystem.remove(self._pid_file) |
| 155 return | 165 return |
| 156 | 166 |
| 157 if self._is_win: | 167 if self._is_win: |
| 158 self._executive.kill_process(self._pid) | 168 self._executive.kill_process(self._pid) |
| 159 return | 169 return |
| 160 | 170 |
| 161 proc = self._executive.popen([self._port_obj.path_to_apache(), | 171 proc = self._executive.popen( |
| 162 '-f', self._port_obj.path_to_apache_config
_file(), | 172 [self._port_obj.path_to_apache(), '-f', self._port_obj.path_to_apach
e_config_file(), '-c', |
| 163 '-c', 'PidFile "%s"' % self._pid_file, | 173 'PidFile "%s"' % self._pid_file, '-k', 'stop'], |
| 164 '-k', 'stop'], stderr=self._executive.PIPE
) | 174 stderr=self._executive.PIPE) |
| 165 proc.wait() | 175 proc.wait() |
| 166 retval = proc.returncode | 176 retval = proc.returncode |
| 167 err = proc.stderr.read() | 177 err = proc.stderr.read() |
| 168 if retval or len(err): | 178 if retval or len(err): |
| 169 raise server_base.ServerError('Failed to stop %s: %s' % (self._name,
err)) | 179 raise server_base.ServerError('Failed to stop %s: %s' % (self._name,
err)) |
| 170 | 180 |
| 171 # For some reason apache isn't guaranteed to have actually stopped after | 181 # For some reason apache isn't guaranteed to have actually stopped after |
| 172 # the stop command returns, so we wait a little while longer for the | 182 # the stop command returns, so we wait a little while longer for the |
| 173 # pid file to be removed. | 183 # pid file to be removed. |
| 174 if not self._wait_for_action(lambda: not self._filesystem.exists(self._p
id_file)): | 184 if not self._wait_for_action(lambda: not self._filesystem.exists(self._p
id_file)): |
| 175 raise server_base.ServerError('Failed to stop %s: pid file still exi
sts' % self._name) | 185 raise server_base.ServerError('Failed to stop %s: pid file still exi
sts' % self._name) |
| OLD | NEW |