def sigchld_handler(signum, frame): _, status = os.waitpid(-1, 0) if os.WIFEXITED(status): os._exit(status) else: logger.error("child exited with signal %d" % os.WTERMSIG(status)) os._exit(os.WTERMSIG(status) + 128)
def sync_local_mirror(config, multipidfile_state): if config["CDIMAGE_NOSYNC"]: return capproject = config.capproject sync_lock = os.path.join(config.root, "etc", ".lock-archive-sync") if not multipidfile_state: log_marker("Syncing %s mirror" % capproject) # Acquire lock to allow parallel builds to ensure a consistent # archive. try: subprocess.check_call(["lockfile", "-r", "4", sync_lock]) except subprocess.CalledProcessError: logger.error("Couldn't acquire archive sync lock!") raise try: anonftpsync(config) finally: osextras.unlink_force(sync_lock) else: log_marker( "Parallel build; waiting for %s mirror to sync" % capproject) try: subprocess.check_call(["lockfile", "-8", "-r", "450", sync_lock]) except subprocess.CalledProcessError: logger.error("Timed out waiting for archive sync lock!") raise osextras.unlink_force(sync_lock)
def lock_build_image_set(config): project = config.project if config["UBUNTU_DEFAULTS_LOCALE"] == "zh_CN": project = "ubuntu-chinese-edition" if config.distribution == "ubuntu": full_series = config.series else: full_series = "%s-%s" % (config.distribution, config.series) lock_path = os.path.join( config.root, "etc", ".lock-build-image-set-%s-%s-%s" % (project, full_series, config.image_type)) try: subprocess.check_call(["lockfile", "-l", "7200", "-r", "0", lock_path]) except subprocess.CalledProcessError: logger.error("Another image set is already building!") raise try: yield finally: osextras.unlink_force(lock_path)
def build_image_set_locked(config, options, multipidfile_state): image_type = config.image_type config["CDIMAGE_DATE"] = date = next_build_id(config, image_type) log_path = None try: configure_for_project(config) log_path = open_log(config) if want_live_builds(options): log_marker("Building live filesystems") live_successful = run_live_builds(config) config.limit_arches(live_successful) else: tracker_set_rebuild_status(config, [0, 1], 2) if not is_live_fs_only(config): sync_local_mirror(config, multipidfile_state) if config["LOCAL"]: log_marker("Updating archive of local packages") update_local_indices(config) build_britney(config) log_marker("Extracting debootstrap scripts") extract_debootstrap(config) if config["UBUNTU_DEFAULTS_LOCALE"]: build_ubuntu_defaults_locale(config) elif is_live_fs_only(config): build_livecd_base(config) else: if not config["CDIMAGE_PREINSTALLED"]: log_marker("Germinating") germination = Germination(config) germination.run() log_marker("Generating new task lists") germinate_output = germination.output(config.project) germinate_output.write_tasks() log_marker("Checking for other task changes") germinate_output.update_tasks(date) if (config["CDIMAGE_LIVE"] or config["CDIMAGE_SQUASHFS_BASE"] or config["CDIMAGE_PREINSTALLED"]): log_marker("Downloading live filesystem images") download_live_filesystems(config) configure_splash(config) run_debian_cd(config) fix_permissions(config) # Temporarily turned off for live builds. if (config["CDIMAGE_INSTALL_BASE"] and not config["CDIMAGE_ADDON"] and not config["CDIMAGE_PREINSTALLED"]): log_marker("Producing installability report") check_installable(config) if not config["DEBUG"] and not config["CDIMAGE_NOPUBLISH"]: log_marker("Publishing") tree = Tree.get_daily(config) publisher = Publisher.get_daily(tree, image_type) publisher.publish(date) log_marker("Purging old images") publisher.purge() log_marker("Triggering mirrors") trigger_mirrors(config) log_marker("Finished") return True except Exception as e: for line in traceback.format_exc().splitlines(): logger.error(line) sys.stdout.flush() sys.stderr.flush() if not isinstance(e, LiveBuildsFailed): notify_failure(config, log_path) return False
def sigalrm_handler(signum, frame): logger.error("%s took too long, terminating ..." % command[0]) os.kill(-subp.pid, signal.SIGTERM)
def publish(self, date): self.new_publish_dir(date) published = [] self.checksum_dirs = [] if not self.config["CDIMAGE_ONLYSOURCE"]: for arch in self.config.arches: published.extend( list(self.publish_binary(self.publish_type, arch, date))) if self.project == "edubuntu" and self.publish_type == "server": for arch in self.config.arches: published.extend( list(self.publish_binary("serveraddon", arch, date))) published.extend(list(self.publish_source(date))) if not published: logger.warning("No CDs produced!") return target_dir = os.path.join(self.publish_base, date) source_report = os.path.join( self.britney_report, "%s_probs.html" % self.config.series) target_report = os.path.join(target_dir, "report.html") if (self.config["CDIMAGE_INSTALL_BASE"] and os.path.exists(source_report)): shutil.copy2(source_report, target_report) else: osextras.unlink_force(target_report) if not self.config["CDIMAGE_ONLYSOURCE"]: checksum_directory( self.config, target_dir, old_directories=self.checksum_dirs, map_expr=r"s/\.\(img\|img\.gz\|iso\|iso\.gz\|tar\.gz\)$/.raw/") subprocess.check_call( [os.path.join(self.config.root, "bin", "make-web-indices"), target_dir, self.config.series, "daily"]) target_dir_source = os.path.join(target_dir, "source") if os.path.isdir(target_dir_source): checksum_directory( self.config, target_dir_source, old_directories=[os.path.join(self.image_output, "src")], map_expr=r"s/\.\(img\|img\.gz\|iso\|iso\.gz\|tar\.gz\)$/.raw/") subprocess.check_call( [os.path.join(self.config.root, "bin", "make-web-indices"), target_dir_source, self.config.series, "daily"]) if (self.image_type.endswith("-live") or self.image_type.endswith("dvd")): # Create and publish metalink files. md5sums_metalink = os.path.join(target_dir, "MD5SUMS-metalink") md5sums_metalink_gpg = os.path.join( target_dir, "MD5SUMS-metalink.gpg") osextras.unlink_force(md5sums_metalink) osextras.unlink_force(md5sums_metalink_gpg) basedir, reldir = self.metalink_dirs(date) if subprocess.call([ os.path.join(self.config.root, "bin", "make-metalink"), basedir, self.config.series, reldir, "cdimage.ubuntu.com", ]) == 0: metalink_checksum_directory(self.config, target_dir) else: for name in os.listdir(target_dir): if name.endswith(".metalink"): osextras.unlink_force(os.path.join(target_dir, name)) publish_current = os.path.join(self.publish_base, "current") osextras.unlink_force(publish_current) os.symlink(date, publish_current) manifest_lock = os.path.join( self.config.root, "etc", ".lock-manifest-daily") try: subprocess.check_call(["lockfile", "-r", "4", manifest_lock]) except subprocess.CalledProcessError: logger.error("Couldn't acquire manifest-daily lock!") raise try: manifest_daily = os.path.join( self.tree.directory, ".manifest-daily") with AtomicFile(manifest_daily) as manifest_daily_file: for line in self.tree.manifest(): print(line, file=manifest_daily_file) os.chmod( manifest_daily, os.stat(manifest_daily).st_mode | stat.S_IWGRP) # Create timestamps for this run. # TODO cjwatson 20120807: Shouldn't these be in www/full # rather than www/full[/project]? trace_dir = os.path.join(self.full_tree, ".trace") osextras.ensuredir(trace_dir) fqdn = socket.getfqdn() with open(os.path.join(trace_dir, fqdn), "w") as trace_file: subprocess.check_call(["date", "-u"], stdout=trace_file) finally: osextras.unlink_force(manifest_lock) subprocess.check_call([ os.path.join(self.config.root, "bin", "post-qa"), date, ] + published)