mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 10:31:35 +00:00
Merge pull request #2915 from scotty-c/master
This commit adds the functionality to run the qemu container detached
This commit is contained in:
commit
d25cf07628
@ -40,6 +40,7 @@ type QemuConfig struct {
|
|||||||
Memory string
|
Memory string
|
||||||
Accel string
|
Accel string
|
||||||
Containerized bool
|
Containerized bool
|
||||||
|
Detached bool
|
||||||
QemuBinPath string
|
QemuBinPath string
|
||||||
QemuImgPath string
|
QemuImgPath string
|
||||||
PublishedPorts []string
|
PublishedPorts []string
|
||||||
@ -162,6 +163,7 @@ func runQemu(args []string) {
|
|||||||
// Backend configuration
|
// Backend configuration
|
||||||
qemuContainerized := flags.Bool("containerized", false, "Run qemu in a container")
|
qemuContainerized := flags.Bool("containerized", false, "Run qemu in a container")
|
||||||
qemuCmd := flags.String("qemu", "", "Path to the qemu binary (otherwise look in $PATH)")
|
qemuCmd := flags.String("qemu", "", "Path to the qemu binary (otherwise look in $PATH)")
|
||||||
|
qemuDetached := flags.Bool("detached", false, "Set qemu container to run in the background")
|
||||||
|
|
||||||
// Generate UUID, so that /sys/class/dmi/id/product_uuid is populated
|
// Generate UUID, so that /sys/class/dmi/id/product_uuid is populated
|
||||||
vmUUID := uuid.New()
|
vmUUID := uuid.New()
|
||||||
@ -306,6 +308,7 @@ func runQemu(args []string) {
|
|||||||
Memory: *mem,
|
Memory: *mem,
|
||||||
Accel: *accel,
|
Accel: *accel,
|
||||||
Containerized: *qemuContainerized,
|
Containerized: *qemuContainerized,
|
||||||
|
Detached: *qemuDetached,
|
||||||
QemuBinPath: *qemuCmd,
|
QemuBinPath: *qemuCmd,
|
||||||
PublishedPorts: publishFlags,
|
PublishedPorts: publishFlags,
|
||||||
NetdevConfig: netdevConfig,
|
NetdevConfig: netdevConfig,
|
||||||
@ -363,6 +366,11 @@ func runQemuLocal(config QemuConfig) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detached mode is only supported in a container.
|
||||||
|
if config.Detached == true {
|
||||||
|
return fmt.Errorf("Detached mode is only supported when running in a container, not locally")
|
||||||
|
}
|
||||||
|
|
||||||
qemuCmd := exec.Command(config.QemuBinPath, args...)
|
qemuCmd := exec.Command(config.QemuBinPath, args...)
|
||||||
// If verbosity is enabled print out the full path/arguments
|
// If verbosity is enabled print out the full path/arguments
|
||||||
log.Debugf("%v\n", qemuCmd.Args)
|
log.Debugf("%v\n", qemuCmd.Args)
|
||||||
@ -427,6 +435,10 @@ func runQemuContainer(config QemuConfig) error {
|
|||||||
dockerArgs = append(dockerArgs, "--device", "/dev/kvm")
|
dockerArgs = append(dockerArgs, "--device", "/dev/kvm")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Detached == true {
|
||||||
|
dockerArgs = append(dockerArgs, "-d")
|
||||||
|
}
|
||||||
|
|
||||||
if config.PublishedPorts != nil && len(config.PublishedPorts) > 0 {
|
if config.PublishedPorts != nil && len(config.PublishedPorts) > 0 {
|
||||||
forwardings, err := buildDockerForwardings(config.PublishedPorts)
|
forwardings, err := buildDockerForwardings(config.PublishedPorts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user