本文整理汇总了Golang中github.com/juju/utils.RunCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang RunCommand函数的具体用法?Golang RunCommand怎么用?Golang RunCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RunCommand函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestRunCommandNonZeroExit
func (s *commandSuite) TestRunCommandNonZeroExit(c *gc.C) {
content := `#!/bin/bash --norc
echo stdout
exit 42
`
patchExecutable(s, c.MkDir(), "test-output", content)
output, err := utils.RunCommand("test-output")
c.Assert(err, gc.ErrorMatches, `exit status 42`)
c.Assert(output, gc.Equals, "stdout\n")
}
示例2: TestRunCommandCombinesOutput
func (s *commandSuite) TestRunCommandCombinesOutput(c *gc.C) {
content := `#!/bin/bash --norc
echo stdout
echo stderr 1>&2
`
patchExecutable(s, c.MkDir(), "test-output", content)
output, err := utils.RunCommand("test-output")
c.Assert(err, gc.IsNil)
c.Assert(output, gc.Equals, "stdout\nstderr\n")
}
示例3: TestRunCommandNonZeroExit
func (s *commandSuite) TestRunCommandNonZeroExit(c *gc.C) {
var content string
var cmdName string
var expect string
if runtime.GOOS != "windows" {
content = `#!/bin/bash --norc
echo stdout
exit 42
`
cmdName = "test-output"
expect = "stdout\n"
} else {
content = `@echo off
echo stdout
exit 42
`
cmdName = "test-output.bat"
expect = "stdout\r\n"
}
patchExecutable(s, c.MkDir(), cmdName, content)
output, err := utils.RunCommand("test-output")
c.Assert(err, gc.ErrorMatches, `exit status 42`)
c.Assert(output, gc.Equals, expect)
}
示例4: TestRunCommandCombinesOutput
func (s *commandSuite) TestRunCommandCombinesOutput(c *gc.C) {
var content string
var cmdName string
var expect string
if runtime.GOOS != "windows" {
content = `#!/bin/bash --norc
echo stdout
echo stderr 1>&2
`
cmdName = "test-output"
expect = "stdout\nstderr\n"
} else {
content = `@echo off
echo stdout
echo stderr 1>&2
`
cmdName = "test-output.bat"
expect = "stdout\r\nstderr \r\n"
}
patchExecutable(s, c.MkDir(), cmdName, content)
output, err := utils.RunCommand("test-output")
c.Assert(err, gc.IsNil)
c.Assert(output, gc.Equals, expect)
}
示例5: IsPackageInstalled
// IsPackageInstalled uses dpkg-query to determine if the `packageName`
// package is installed.
func IsPackageInstalled(packageName string) bool {
_, err := utils.RunCommand("dpkg-query", "--status", packageName)
return err == nil
}
示例6: runSSHImportId
func runSSHImportId(keyId string) (string, error) {
return utils.RunCommand("ssh-import-id", "-o", "-", keyId)
}
示例7: installMongod
func installMongod(operatingsystem string, numaCtl bool) error {
// fetch the packaging configuration manager for the current operating system.
pacconfer, err := config.NewPackagingConfigurer(operatingsystem)
if err != nil {
return err
}
// fetch the package manager implementation for the current operating system.
pacman, err := manager.NewPackageManager(operatingsystem)
if err != nil {
return err
}
// Only Quantal requires the PPA.
if operatingsystem == "quantal" {
// install python-software-properties:
if err := pacman.InstallPrerequisite(); err != nil {
return err
}
if err := pacman.AddRepository("ppa:juju/stable"); err != nil {
return err
}
}
// CentOS requires "epel-release" for the epel repo mongodb-server is in.
if operatingsystem == "centos7" {
// install epel-release
if err := pacman.Install("epel-release"); err != nil {
return err
}
}
mongoPkg := packageForSeries(operatingsystem)
pkgs := []string{mongoPkg}
if numaCtl {
pkgs = []string{mongoPkg, numaCtlPkg}
logger.Infof("installing %s and %s", mongoPkg, numaCtlPkg)
} else {
logger.Infof("installing %s", mongoPkg)
}
for i, _ := range pkgs {
// apply release targeting if needed.
if pacconfer.IsCloudArchivePackage(pkgs[i]) {
pkgs[i] = strings.Join(pacconfer.ApplyCloudArchiveTarget(pkgs[i]), " ")
}
if err := pacman.Install(pkgs[i]); err != nil {
return err
}
}
// Work around SELinux on centos7
if operatingsystem == "centos7" {
cmd := []string{"chcon", "-R", "-v", "-t", "mongod_var_lib_t", "/var/lib/juju/"}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
logger.Errorf("chcon failed to change file security context error %s", err)
return err
}
cmd = []string{"semanage", "port", "-a", "-t", "mongod_port_t", "-p", "tcp", strconv.Itoa(environs.DefaultStatePort)}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
if !strings.Contains(err.Error(), "exit status 1") {
logger.Errorf("semanage failed to provide access on port %d error %s", environs.DefaultStatePort, err)
return err
}
}
}
return nil
}
示例8: installMongod
func installMongod(operatingsystem string, numaCtl bool) error {
// fetch the packaging configuration manager for the current operating system.
pacconfer, err := config.NewPackagingConfigurer(operatingsystem)
if err != nil {
return err
}
// fetch the package manager implementation for the current operating system.
pacman, err := manager.NewPackageManager(operatingsystem)
if err != nil {
return err
}
// CentOS requires "epel-release" for the epel repo mongodb-server is in.
if operatingsystem == "centos7" {
// install epel-release
if err := pacman.Install("epel-release"); err != nil {
return err
}
}
mongoPkgs, fallbackPkgs := packagesForSeries(operatingsystem)
if numaCtl {
logger.Infof("installing %v and %s", mongoPkgs, numaCtlPkg)
if err = installPackage(numaCtlPkg, pacconfer, pacman); err != nil {
return errors.Trace(err)
}
} else {
logger.Infof("installing %v", mongoPkgs)
}
for i := range mongoPkgs {
if err = installPackage(mongoPkgs[i], pacconfer, pacman); err != nil {
break
}
}
if err != nil && len(fallbackPkgs) == 0 {
return errors.Trace(err)
}
if err != nil {
logger.Errorf("installing mongo failed: %v", err)
logger.Infof("will try fallback packages %v", fallbackPkgs)
for i := range fallbackPkgs {
if err = installPackage(fallbackPkgs[i], pacconfer, pacman); err != nil {
return errors.Trace(err)
}
}
}
// Work around SELinux on centos7
if operatingsystem == "centos7" {
cmd := []string{"chcon", "-R", "-v", "-t", "mongod_var_lib_t", "/var/lib/juju/"}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
logger.Errorf("chcon failed to change file security context error %s", err)
return err
}
cmd = []string{"semanage", "port", "-a", "-t", "mongod_port_t", "-p", "tcp", strconv.Itoa(environs.DefaultStatePort)}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
if !strings.Contains(err.Error(), "exit status 1") {
logger.Errorf("semanage failed to provide access on port %d error %s", environs.DefaultStatePort, err)
return err
}
}
}
return nil
}
示例9: installMongod
func installMongod(numaCtl bool) error {
series := version.Current.Series
pacconfer, err := getPackagingConfigurer()
if err != nil {
return err
}
pacman, err := getPackageManager()
if err != nil {
return err
}
// Only Quantal requires the PPA.
if series == "quantal" {
// install python-software-properties:
if err := pacman.InstallPrerequisite(); err != nil {
return err
}
if err := pacman.AddRepository("ppa:juju/stable"); err != nil {
return err
}
}
// CentOS requires "epel-release" for the epel repo mongodb-server is in.
if series == "centos7" {
// install epel-release
if err := pacman.Install("epel-release"); err != nil {
return err
}
}
mongoPkg := packageForSeries(series)
pkgs := []string{mongoPkg}
if numaCtl {
pkgs = []string{mongoPkg, numaCtlPkg}
logger.Infof("installing %s and %s", mongoPkg, numaCtlPkg)
} else {
logger.Infof("installing %s", mongoPkg)
}
for i, _ := range pkgs {
// apply release targeting if needed.
if pacconfer.IsCloudArchivePackage(pkgs[i]) {
pkgs[i] = strings.Join(pacconfer.ApplyCloudArchiveTarget(pkgs[i]), " ")
}
if err := pacman.Install(pkgs[i]); err != nil {
return err
}
}
// Work around SELinux on centos7
if series == "centos7" {
cmd := []string{"chcon", "-R", "-v", "-t", "mongod_var_lib_t", "/var/lib/juju/"}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
logger.Infof("chcon error %s", err)
logger.Infof("chcon error %s", err.Error())
return err
}
cmd = []string{"semanage", "port", "-a", "-t", "mongod_port_t", "-p", "tcp", "37017"}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
if !strings.Contains(err.Error(), "exit status 1") {
return err
}
}
}
return nil
}
示例10: run
// run the command and return the combined output.
func run(command string, args ...string) (output string, err error) {
logger.Tracef("%s %v", command, args)
output, err = utils.RunCommand(command, args...)
logger.Tracef("output: %v", output)
return output, err
}