本文整理汇总了Golang中github.com/juju/deputy.Deputy.Run方法的典型用法代码示例。如果您正苦于以下问题:Golang Deputy.Run方法的具体用法?Golang Deputy.Run怎么用?Golang Deputy.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/deputy.Deputy
的用法示例。
在下文中一共展示了Deputy.Run方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Launch
// Launch runs a new docker container with the given process data.
func Launch(p charm.Process) (ProcDetails, error) {
args, err := launchArgs(p)
if err != nil {
return ProcDetails{}, err
}
d := deputy.Deputy{
Errors: deputy.FromStderr,
}
cmd := execCommand("docker", args...)
out := &bytes.Buffer{}
cmd.Stdout = out
if err := d.Run(cmd); err != nil {
return ProcDetails{}, err
}
id := string(bytes.TrimSpace(out.Bytes()))
status, err := inspect(id)
if err != nil {
return ProcDetails{}, fmt.Errorf("can't get status for container %q: %s", id, err)
}
return ProcDetails{
ID: strings.TrimPrefix(status.Name, "/"),
Status: ProcStatus{
State: status.brief(),
},
}, nil
}
示例2: inspect
// inspect calls docker inspect and returns the unmarshaled json response.
func inspect(id string) (status, error) {
cmd := execCommand("docker", "inspect", id)
out := &bytes.Buffer{}
cmd.Stdout = out
d := deputy.Deputy{
Errors: deputy.FromStderr,
}
if err := d.Run(cmd); err != nil {
return status{}, err
}
return statusFromInspect(id, out.Bytes())
}
示例3: Example
func Example() {
// Make a new deputy that'll return the data written to stderr as the error
// message, log everything written to stdout to this application's log, and
// timeout after 30 seconds.
d := deputy.Deputy{
Errors: deputy.FromStderr,
StdoutLog: func(b []byte) { log.Print(string(b)) },
Timeout: time.Second * 30,
}
if err := d.Run(exec.Command("foo")); err != nil {
log.Print(err)
}
}
示例4: Destroy
// Destroy stops and removes the docker container with the given id.
func Destroy(id string) error {
d := deputy.Deputy{
Errors: deputy.FromStderr,
}
cmd := execCommand("docker", "stop", id)
if err := d.Run(cmd); err != nil {
return fmt.Errorf("error while stopping container %q: %s", err)
}
cmd = execCommand("docker", "rm", id)
if err := d.Run(cmd); err != nil {
return fmt.Errorf("error while removing container %q: %s", err)
}
return nil
}
示例5: makeCatalogs
func makeCatalogs(makeCatalogsPath, repoPath string, execTimeout time.Duration) {
makecatalogsCmd := exec.Command(
makeCatalogsPath,
repoPath,
)
d := deputy.Deputy{
Errors: deputy.FromStderr,
StdoutLog: func(b []byte) { log.Println(string(b)) },
Timeout: time.Second * execTimeout,
}
if err := d.Run(makecatalogsCmd); err != nil {
log.Println(err)
return
}
}
示例6: execute
func execute(cmd string) (string, error) {
if len(cmd) == 0 {
return "", ErrNoCommand
}
var value string
d := deputy.Deputy{
Errors: deputy.FromStderr,
StdoutLog: func(b []byte) {
value = string(b)
},
}
if err := d.Run(exec.Command("sh", "-c", cmd)); err != nil {
return "", err
}
return value, nil
}
示例7: runAutopkg
func runAutopkg(recipe, reportsPath, cmdPath string, check bool, execTimeout time.Duration) autopkgReport {
autopkgCmd := exec.Command(cmdPath, "run", "--report-plist="+reportsPath+"/"+recipe)
if check {
autopkgCmd.Args = append(autopkgCmd.Args, "--check")
}
autopkgCmd.Args = append(autopkgCmd.Args, recipe)
d := deputy.Deputy{
Errors: deputy.FromStderr,
StdoutLog: func(b []byte) { log.Print(string(b)) },
Timeout: time.Second * execTimeout,
}
if err := d.Run(autopkgCmd); err != nil {
log.Println(err)
return autopkgReport{}
}
report, err := readReportPlist(reportsPath + "/" + recipe)
if err != nil {
log.Println(err)
return autopkgReport{}
}
return report
}