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 }