start_journal_remote,
)
from mkosi.run import (
+ Popen,
apivfs_options,
chroot_cmd,
chroot_options,
run_systemd_tool("coredumpctl", args, config)
+def start_storage_target_mode(config: Config) -> AbstractContextManager[Optional[Popen]]:
+ if config.storage_target_mode == ConfigFeature.disabled:
+ return contextlib.nullcontext()
+
+ if config.storage_target_mode == ConfigFeature.auto and os.getuid() != 0:
+ return contextlib.nullcontext()
+
+ if config.output_format != OutputFormat.disk:
+ if config.storage_target_mode == ConfigFeature.enabled:
+ die("Storage target mode is only supported for the 'disk' output format")
+
+ return contextlib.nullcontext()
+
+ if not config.find_binary("/usr/lib/systemd/systemd-storagetm"):
+ if config.storage_target_mode == ConfigFeature.enabled:
+ die("Storage target mode enabled but systemd-storagetm is not installed")
+
+ return contextlib.nullcontext()
+
+ return 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(),
+ ),
+ )
+
+
def run_serve(args: Args, config: Config) -> None:
"""Serve the output directory via a tiny HTTP server"""
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"],
)
)
- 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(),
- ),
- )
- )
+ storagetm = stack.enter_context(start_storage_target_mode(config))
+ # If we run systemd-storagetm with run0, it replaces the foreground process group with its own which
+ # means the http process doesn't get SIGINT from the terminal, so let's send it ourselves in that
+ # case.
+ if storagetm and os.getuid() != 0:
storagetm.wait()
http.send_signal(signal.SIGINT)
- http.wait()
-
def generate_key_cert_pair(args: Args) -> None:
"""Generate a private key and accompanying X509 certificate using openssl"""
credentials: dict[str, str]
kernel_command_line_extra: list[str]
register: ConfigFeature
+ storage_target_mode: ConfigFeature
runtime_trees: list[ConfigTree]
runtime_size: Optional[int]
runtime_scratch: ConfigFeature
default=ConfigFeature.auto,
help="Register booted vm/container with systemd-machined",
),
+ ConfigSetting(
+ dest="storage_target_mode",
+ metavar="FEATURE",
+ section="Runtime",
+ parse=config_parse_feature,
+ default=ConfigFeature.auto,
+ help="Run systemd-storagetm as part of the serve verb",
+ ),
]
SETTINGS_LOOKUP_BY_NAME = {name: s for s in SETTINGS for name in [s.name, *s.compat_names]}
SETTINGS_LOOKUP_BY_DEST = {s.dest: s for s in SETTINGS}
Machine: {config.machine_or_name()}
Forward Journal: {none_to_none(config.forward_journal)}
Register guest with machined: {config.register}
+ Storage Target Mode: {config.storage_target_mode}
Virtual Machine Monitor: {config.vmm}
Console: {config.console}
of file if your workload produces more than `4G` worth of journal
data.
+`StorageTargetMode=`, `--storage-target-mode=`
+: Specifies whether the `serve` verb should start
+ **systemd-storagetm** to serve disk images over NVME-TCP. Takes a
+ boolean value or `auto`. If enabled, systemd-storagetm is always
+ started and mkosi will fail if it cannot start systemd-storagetm. If
+ disabled, systemd-storagetm is never started. If `auto`,
+ systemd-storagetm will be started if a disk image is being built,
+ the systemd-storagetm binary is found and `mkosi serve` is being
+ invoked as the root user.
+
`SysupdateDirectory=`, `--sysupdate-directory=`
: Path to a directory containing systemd-sysupdate transfer definition
files that are used by `mkosi sysupdate`. If `mkosi.sysupdate/`