| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 def _remove_stale_logs(self): | 152 def _remove_stale_logs(self): |
| 153 """This routine can be overridden by subclasses to try and remove logs | 153 """This routine can be overridden by subclasses to try and remove logs |
| 154 left over from a prior run. This routine should log warnings if the | 154 left over from a prior run. This routine should log warnings if the |
| 155 files cannot be deleted, but should not fail unless failure to | 155 files cannot be deleted, but should not fail unless failure to |
| 156 delete the logs will actually cause start() to fail.""" | 156 delete the logs will actually cause start() to fail.""" |
| 157 # Sometimes logs are open in other processes but they should clear event
ually. | 157 # Sometimes logs are open in other processes but they should clear event
ually. |
| 158 for log_prefix in self._log_prefixes: | 158 for log_prefix in self._log_prefixes: |
| 159 try: | 159 try: |
| 160 self._remove_log_files(self._output_dir, log_prefix) | 160 self._remove_log_files(self._output_dir, log_prefix) |
| 161 except OSError as e: | 161 except OSError: |
| 162 _log.warning('Failed to remove old %s %s files' % (self._name, l
og_prefix)) | 162 _log.warning('Failed to remove old %s %s files' % (self._name, l
og_prefix)) |
| 163 | 163 |
| 164 def _spawn_process(self): | 164 def _spawn_process(self): |
| 165 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd
)) | 165 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd
)) |
| 166 self._process = self._executive.popen(self._start_cmd, | 166 self._process = self._executive.popen(self._start_cmd, |
| 167 env=self._env, | 167 env=self._env, |
| 168 cwd=self._cwd, | 168 cwd=self._cwd, |
| 169 stdout=self._stdout, | 169 stdout=self._stdout, |
| 170 stderr=self._stderr) | 170 stderr=self._stderr) |
| 171 pid = self._process.pid | 171 pid = self._process.pid |
| 172 self._filesystem.write_text_file(self._pid_file, str(pid)) | 172 self._filesystem.write_text_file(self._pid_file, str(pid)) |
| 173 return pid | 173 return pid |
| 174 | 174 |
| 175 def _stop_running_server(self): | 175 def _stop_running_server(self): |
| 176 self._wait_for_action(self._check_and_kill) | 176 self._wait_for_action(self._check_and_kill) |
| 177 if self._filesystem.exists(self._pid_file): | 177 if self._filesystem.exists(self._pid_file): |
| 178 self._filesystem.remove(self._pid_file) | 178 self._filesystem.remove(self._pid_file) |
| 179 | 179 |
| 180 def _check_and_kill(self): | 180 def _check_and_kill(self): |
| 181 if self._executive.check_running_pid(self._pid): | 181 if self._executive.check_running_pid(self._pid): |
| 182 _log.debug('pid %d is running, killing it' % self._pid) | 182 _log.debug('pid %d is running, killing it' % self._pid) |
| 183 host = self._port_obj.host | |
| 184 self._executive.kill_process(self._pid) | 183 self._executive.kill_process(self._pid) |
| 185 return False | 184 return False |
| 186 else: | 185 else: |
| 187 _log.debug('pid %d is not running' % self._pid) | 186 _log.debug('pid %d is not running' % self._pid) |
| 188 | 187 |
| 189 return True | 188 return True |
| 190 | 189 |
| 191 def _remove_pid_file(self): | 190 def _remove_pid_file(self): |
| 192 if self._filesystem.exists(self._pid_file): | 191 if self._filesystem.exists(self._pid_file): |
| 193 self._filesystem.remove(self._pid_file) | 192 self._filesystem.remove(self._pid_file) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 except IOError as e: | 273 except IOError as e: |
| 275 if e.errno in (errno.EALREADY, errno.EADDRINUSE): | 274 if e.errno in (errno.EALREADY, errno.EADDRINUSE): |
| 276 raise ServerError('Port %d is already in use.' % port) | 275 raise ServerError('Port %d is already in use.' % port) |
| 277 elif self._platform.is_win() and e.errno in (errno.WSAEACCES,):
# pylint: disable=E1101 | 276 elif self._platform.is_win() and e.errno in (errno.WSAEACCES,):
# pylint: disable=E1101 |
| 278 raise ServerError('Port %d is already in use.' % port) | 277 raise ServerError('Port %d is already in use.' % port) |
| 279 else: | 278 else: |
| 280 raise | 279 raise |
| 281 finally: | 280 finally: |
| 282 s.close() | 281 s.close() |
| 283 _log.debug('all ports are available') | 282 _log.debug('all ports are available') |
| OLD | NEW |