github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/container/kvm/run.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package kvm
     5  
     6  import (
     7  	"os/exec"
     8  )
     9  
    10  // This is the user on ubuntu. I don't know what the user would be on other
    11  // linux distros. At the time of this writing we are only supporting ubuntu on
    12  // ubuntu for kvm containers in Juju.
    13  const libvirtUser = "libvirt-qemu"
    14  
    15  // runFunc provides the signature for running an external
    16  // command and returning the combined output.
    17  // The first parameter, if non-empty will use the input
    18  // path as the working directory for the command.
    19  // NOTE: if changing runFunc, remember to edit BOTH copies of
    20  // runAsLibvirt() in run_other.go and run_linux.go.  One doesn't
    21  // compile on linux, thus easily missed.
    22  type runFunc func(string, string, ...string) (string, error)
    23  
    24  // run the command and return the combined output.
    25  func run(dir, command string, args ...string) (string, error) {
    26  	logger.Debugf("(%s) %s %v", dir, command, args)
    27  
    28  	cmd := exec.Command(command, args...)
    29  	if dir != "" {
    30  		cmd.Dir = dir
    31  	}
    32  
    33  	out, err := cmd.CombinedOutput()
    34  	output := string(out)
    35  
    36  	logger.Debugf("output: %v", output)
    37  	return output, err
    38  }