f-37: add systemd-run

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-08-14 00:27:25 +02:00
commit c89e3f64de
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 14 additions and 3 deletions

View file

@ -1,5 +1,9 @@
package qemu
func ScopeName(vmName string) string {
return "two-vm-" + vmName + ".scope"
}
type DiskConfig struct {
Path string
Dev string

View file

@ -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
}