def is_stale_pidfile(pidfile): try: with open(pidfile) as fd: pid = int(fd.read()) except Exception: return False # that's either garbage in the pid-file or a race return not is_process_running(pid)
def get_in_progress(self): in_progress_reports = [] all_entries = yield self.get_report_log_entries() for entry in all_entries[:]: if entry['status'] in ('created', ): if is_process_running(entry['pid']): in_progress_reports.append( (entry['measurements_path'], entry)) defer.returnValue(in_progress_reports)
def get_in_progress(self): in_progress_reports = [] all_entries = yield self.get_report_log_entries() for entry in all_entries[:]: if entry['status'] in ('created',): if is_process_running(entry['pid']): in_progress_reports.append( (entry['measurements_path'], entry) ) defer.returnValue(in_progress_reports)
def get_measurement(measurement_id, compute_size=False): size = -1 measurement_path = FilePath(config.measurements_directory) measurement = measurement_path.child(measurement_id) if not measurement.exists(): raise MeasurementNotFound running = False completed = True keep = False stale = False anomaly = False if measurement.child("measurements.njson.progress").exists(): completed = False try: pid = measurement.child("running.pid").open("r").read() pid = int(pid) if is_process_running(pid): running = True else: stale = True except IOError: stale = True if measurement.child("keep").exists(): keep = True if measurement.child("anomaly").exists(): anomaly = True if compute_size is True: size = directory_usage(measurement.path) measurement_metadata = measurement_id.split("-") test_start_time, country_code, asn, test_name = measurement_metadata[:4] deck_id = "none" if len(measurement_metadata) > 4: deck_id = '-'.join(measurement_metadata[4:]) return { "test_name": test_name, "country_code": country_code, "asn": asn, "test_start_time": test_start_time, "id": measurement_id, "completed": completed, "keep": keep, "running": running, "stale": stale, "size": size, "deck_id": deck_id, "anomaly": anomaly }
def get_incomplete(self): incomplete_reports = [] all_entries = yield self.get_report_log_entries() for entry in all_entries[:]: # This means that the measurement itself is incomplete if entry['completed'] is False: continue if entry['status'] in ('created', ): if not is_process_running(entry['pid']): incomplete_reports.append( (entry['measurements_path'], entry)) elif entry['status'] in ('incomplete', ): incomplete_reports.append((entry['measurements_path'], entry)) defer.returnValue(incomplete_reports)
def get_running_pidfile(): """ :return: This pid of the running ooniprobe-agent instance. :raises: NotRunning if it's not running """ running_pidfile = None for pidfile in [config.system_pid_path, config.user_pid_path]: if not os.path.exists(pidfile): # Didn't find the pid_file continue pid = open(pidfile, "r").read() pid = int(pid) if is_process_running(pid): return pidfile raise NotRunning
def get_incomplete(self): incomplete_reports = [] all_entries = yield self.get_report_log_entries() for entry in all_entries[:]: # This means that the measurement itself is incomplete if entry['completed'] is False: continue if entry['status'] in ('created',): if not is_process_running(entry['pid']): incomplete_reports.append( (entry['measurements_path'], entry) ) elif entry['status'] in ('incomplete',): incomplete_reports.append( (entry['measurements_path'], entry) ) defer.returnValue(incomplete_reports)
def get_measurement(measurement_id, compute_size=False): size = -1 measurement_path = FilePath(config.measurements_directory) measurement = measurement_path.child(measurement_id) if not measurement.exists(): raise MeasurementNotFound running = False completed = True keep = False stale = False if measurement.child("measurements.njson.progress").exists(): completed = False pid = measurement.child("running.pid").open("r").read() pid = int(pid) if is_process_running(pid): running = True else: stale = True if measurement.child("keep").exists(): keep = True if compute_size is True: size = directory_usage(measurement.path) test_start_time, country_code, asn, test_name = \ measurement_id.split("-")[:4] return { "test_name": test_name, "country_code": country_code, "asn": asn, "test_start_time": test_start_time, "id": measurement_id, "completed": completed, "keep": keep, "running": running, "stale": stale, "size": size }