From c89e3f64de11a7e116e6e72c1d1592ad69a6add2 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Fri, 14 Aug 2026 00:27:25 +0200 Subject: [PATCH] f-37: add systemd-run Signed-off-by: GnomeZworc --- internal/qemu/config.go | 4 ++++ internal/qemu/start_linux.go | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/qemu/config.go b/internal/qemu/config.go index 9b50add..2177066 100644 --- a/internal/qemu/config.go +++ b/internal/qemu/config.go @@ -1,5 +1,9 @@ package qemu +func ScopeName(vmName string) string { + return "two-vm-" + vmName + ".scope" +} + type DiskConfig struct { Path string Dev string diff --git a/internal/qemu/start_linux.go b/internal/qemu/start_linux.go index 181bb1d..fa7bcf3 100644 --- a/internal/qemu/start_linux.go +++ b/internal/qemu/start_linux.go @@ -103,9 +103,16 @@ func Start(cfg Config) error { "-daemonize", ) - cmd := exec.Command("qemu-system-x86_64", args...) - if err := cmd.Run(); err != nil { - return fmt.Errorf("qemu-system-x86_64: %w", err) + scopeArgs := append([]string{ + "--scope", + "--unit=" + ScopeName(cfg.Name), + "--collect", + "qemu-system-x86_64", + }, args...) + + cmd := exec.Command("systemd-run", scopeArgs...) + if out, err := cmd.CombinedOutput(); err != nil { + return fmt.Errorf("systemd-run qemu-system-x86_64: %w: %s", err, strings.TrimSpace(string(out))) } return nil }