def start(self): """Start the process. This will block until the Crate cluster is ready to process requests. """ log.info('Starting Crate process') self.process = proc = self.enter_context( subprocess.Popen(self.cmd, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=self.env, universal_newlines=True)) msg = ('CrateDB launching:\n' ' PID: %s\n' ' Logs: %s\n' ' Data: %s') if not self.keep_data: msg += ' (removed on stop)\n' logfile = os.path.join(self.logs_path, self.cluster_name + '.log') log.info(msg, proc.pid, logfile, self.data_path) self.addresses = DotDict({}) self.monitor.consumers.append(AddrConsumer(self._set_addr)) self.monitor.start(proc) line_buf = LineBuffer() self.monitor.consumers.append(line_buf) spinner = cycle(['/', '-', '\\', '|']) def show_spinner(): if sys.stdout.isatty(): print(next(spinner), end='\r') return True try: wait_until(lambda: show_spinner() and _ensure_running(proc) and self.http_host, timeout=60) host = self.addresses.http.host port = self.addresses.http.port wait_until(lambda: _ensure_running(proc) and _is_up(host, port), timeout=30) if _has_ssl(host, port): self.http_url = self.http_url.replace('http://', 'https://') wait_until( lambda: show_spinner() and cluster_state_200(self.http_url), timeout=30) except (SystemError, TimeoutError): if not line_buf.lines: _try_print_log(logfile) else: for line in line_buf.lines: log.error(line) raise SystemExit("Exiting because CrateDB didn't start correctly") else: self.monitor.consumers.remove(line_buf) log.info('Cluster ready to process requests')
def stop(self): if self.process: self.process.terminate() self.process.communicate(timeout=10) self.addresses = DotDict({}) self.http_host = None self.http_url = None if not self.keep_data: path = self.data_path.split(',') for p in path: shutil.rmtree(p)