本文整理匯總了Golang中github.com/megamsys/libgo/exec.OsExecutor.Execute方法的典型用法代碼示例。如果您正苦於以下問題:Golang OsExecutor.Execute方法的具體用法?Golang OsExecutor.Execute怎麽用?Golang OsExecutor.Execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/megamsys/libgo/exec.OsExecutor
的用法示例。
在下文中一共展示了OsExecutor.Execute方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DockerLogExecutor
/*
* Docker log executor executes the ln command and establishes link between the
* docker path and megam-heka reading path.
*/
func DockerLogExecutor(logs *global.DockerLogsInfo) (action.Result, error) {
var e exec.OsExecutor
var commandWords []string
commandWords = strings.Fields(logs.Command)
log.Debug("Command Executor entry: %s\n", logs)
fmt.Println(commandWords)
megam_home, ckberr := config.GetString("megam_home")
if ckberr != nil {
return nil, ckberr
}
dockerName := logs.ContainerName
basePath := megam_home + "logs"
create_dir := path.Join(basePath, dockerName)
if _, err := os.Stat(create_dir); os.IsNotExist(err) {
log.Info("Creating directory: %s\n", create_dir)
if errm := os.MkdirAll(create_dir, 0777); errm != nil {
return nil, errm
}
}
if len(commandWords) > 0 {
if err := e.Execute(commandWords[0], commandWords[1:], nil, nil, nil); err != nil {
return nil, err
}
}
return &logs, nil
}
示例2: CommandExecutor
func CommandExecutor(app *global.AssemblyWithComponents) (action.Result, error) {
var e exec.OsExecutor
var commandWords []string
appName := ""
commandWords = strings.Fields(app.Command)
log.Debug("Command Executor entry: %s\n", app)
megam_home, ckberr := config.GetString("megam_home")
if ckberr != nil {
return nil, ckberr
}
pair, perr := global.ParseKeyValuePair(app.Inputs, "domain")
if perr != nil {
log.Error("Failed to get the domain value : %s", perr)
}
appName = app.Name + "." + pair.Value
basePath := megam_home + "logs"
dir := path.Join(basePath, appName)
fileOutPath := path.Join(dir, appName+"_out")
fileErrPath := path.Join(dir, appName+"_err")
if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Info("Creating directory: %s\n", dir)
if errm := os.MkdirAll(dir, 0777); errm != nil {
return nil, errm
}
}
// open output file
fout, outerr := os.OpenFile(fileOutPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if outerr != nil {
return nil, outerr
}
defer fout.Close()
// open Error file
ferr, errerr := os.OpenFile(fileErrPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if errerr != nil {
return nil, errerr
}
defer ferr.Close()
foutwriter := bufio.NewWriterSize(fout, 1)
ferrwriter := bufio.NewWriterSize(ferr, 1)
log.Debug(commandWords)
log.Debug("Length: %s", len(commandWords))
defer ferrwriter.Flush()
defer foutwriter.Flush()
if len(commandWords) > 0 {
if err := e.Execute(commandWords[0], commandWords[1:], nil, foutwriter, ferrwriter); err != nil {
return nil, err
}
}
return &app, nil
}
示例3: ExecuteCommandOnce
func ExecuteCommandOnce(commandWords []string, w io.Writer) error {
var e exec.OsExecutor
if len(commandWords) > 0 {
if err := e.Execute(commandWords[0], commandWords[1:], nil, w, w); err != nil {
return err
}
}
return nil
}
示例4: TorpedoCommandExecutor
func TorpedoCommandExecutor(command string, app *global.AssemblyWithComponents) (action.Result, error) {
var e exec.OsExecutor
var commandWords []string
ctype := strings.Split(app.ToscaType, ".")
commandWords = strings.Fields(command + " " + ctype[2])
log.Debug("Command Executor entry: %s\n", app)
megam_home, ckberr := config.GetString("megam_home")
if ckberr != nil {
return nil, ckberr
}
appName := app.Name
basePath := megam_home + "logs"
dir := path.Join(basePath, appName)
fileOutPath := path.Join(dir, appName+"_out")
fileErrPath := path.Join(dir, appName+"_err")
if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Info("Creating directory: %s\n", dir)
if errm := os.MkdirAll(dir, 0777); errm != nil {
return nil, errm
}
}
// open output file
fout, outerr := os.OpenFile(fileOutPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if outerr != nil {
return nil, outerr
}
defer fout.Close()
// open Error file
ferr, errerr := os.OpenFile(fileErrPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if errerr != nil {
return nil, errerr
}
defer ferr.Close()
foutwriter := bufio.NewWriter(fout)
ferrwriter := bufio.NewWriter(ferr)
log.Debug(commandWords)
log.Debug("Length: %s", len(commandWords))
defer ferrwriter.Flush()
defer foutwriter.Flush()
if len(commandWords) > 0 {
if err := e.Execute(commandWords[0], commandWords[1:len(commandWords)], nil, foutwriter, ferrwriter); err != nil {
fmt.Println(err)
return nil, err
}
}
return &app, nil
}
示例5: DockerNetworkExecutor
/*
* Docker network executor executes the script for the container to be exposed
* publicly. Bridge, ip address, container id and gateway are required.
*/
func DockerNetworkExecutor(networks *global.DockerNetworksInfo) (action.Result, error) {
var e exec.OsExecutor
var commandWords []string
commandWords = strings.Fields(networks.Command)
log.Debug("Command Executor entry: %s\n", networks)
log.Debug(commandWords)
megam_home, ckberr := config.GetString("megam_home")
if ckberr != nil {
return nil, ckberr
}
appName := networks.ContainerId
basePath := megam_home + "logs"
dir := path.Join(basePath, appName)
fileOutPath := path.Join(dir, appName+"_out")
fileErrPath := path.Join(dir, appName+"_err")
if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Info("Creating directory: %s\n", dir)
if errm := os.MkdirAll(dir, 0777); errm != nil {
return nil, errm
}
}
// open output file
fout, outerr := os.OpenFile(fileOutPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if outerr != nil {
return nil, outerr
}
defer fout.Close()
// open Error file
ferr, errerr := os.OpenFile(fileErrPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if errerr != nil {
return nil, errerr
}
defer ferr.Close()
foutwriter := bufio.NewWriter(fout)
ferrwriter := bufio.NewWriter(ferr)
log.Debug(commandWords)
log.Debug("Length: %s", len(commandWords))
defer ferrwriter.Flush()
defer foutwriter.Flush()
if len(commandWords) > 0 {
if err := e.Execute(commandWords[0], commandWords[1:], nil, foutwriter, ferrwriter); err != nil {
return nil, err
}
}
return &networks, nil
}
示例6: networkExecutor
func networkExecutor(networks *runNetworkActionsArgs) (action.Result, error) {
var e exec.OsExecutor
var commandWords []string
commandWords = strings.Fields(networks.Command)
if len(commandWords) > 0 {
if err := e.Execute(commandWords[0], commandWords[1:], nil, nil, nil); err != nil {
_ = provision.EventNotify(constants.StatusContainerNetworkFailure)
return nil, err
}
}
_ = provision.EventNotify(constants.StatusContainerNetworkSuccess)
return &networks, nil
}