From: Daan De Meyer Date: Sat, 8 Feb 2025 11:25:57 +0000 (+0100) Subject: Start systemd-storagetm in mkosi serve as well if available X-Git-Tag: v26~404 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f8ee53c41d2944f996de9a7c53cb64b059f33d6;p=thirdparty%2Fmkosi.git Start systemd-storagetm in mkosi serve as well if available Allows accessing a disk image over NVME-TCP instead of having to download it completely over HTTP. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index de8cca331..4b8d5f940 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -13,6 +13,7 @@ import re import resource import shlex import shutil +import signal import socket import stat import subprocess @@ -107,6 +108,7 @@ from mkosi.run import ( finalize_passwd_symlinks, fork_and_wait, run, + spawn, workdir, ) from mkosi.sandbox import ( @@ -4250,16 +4252,45 @@ def run_coredumpctl(args: Args, config: Config) -> None: def run_serve(args: Args, config: Config) -> None: """Serve the output directory via a tiny HTTP server""" - run( - [python_binary(config), "-m", "http.server", "8081"], - stdin=sys.stdin, - stdout=sys.stdout, - sandbox=config.sandbox( - network=True, - relaxed=True, - options=["--chdir", config.output_dir_or_cwd()], - ), - ) + with contextlib.ExitStack() as stack: + want_storagetm = config.output_format == OutputFormat.disk and config.find_binary( + "/usr/lib/systemd/systemd-storagetm" + ) + + http = stack.enter_context( + spawn( + [python_binary(config), "-m", "http.server", "8081"], + stdin=sys.stdin, + stdout=sys.stdout, + sandbox=config.sandbox( + network=True, + relaxed=True, + options=["--chdir", config.output_dir_or_cwd()], + ), + foreground=not want_storagetm, + ) + ) + + if want_storagetm: + storagetm = stack.enter_context( + spawn( + ["/usr/lib/systemd/systemd-storagetm", config.output_with_format], + stdin=sys.stdin, + stdout=sys.stdout, + sandbox=config.sandbox( + network=True, + relaxed=True, + options=["--chdir", config.output_dir_or_cwd()], + setup=become_root_cmd(), + ), + foreground=True, + ) + ) + + storagetm.wait() + http.send_signal(signal.SIGINT) + + http.wait() def generate_key_cert_pair(args: Args) -> None: