當前位置: 首頁>>代碼示例>>Golang>>正文


Golang exec.OsExecutor類代碼示例

本文整理匯總了Golang中github.com/megamsys/libgo/exec.OsExecutor的典型用法代碼示例。如果您正苦於以下問題:Golang OsExecutor類的具體用法?Golang OsExecutor怎麽用?Golang OsExecutor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了OsExecutor類的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
}
開發者ID:rajthilakmca,項目名稱:megamgulp,代碼行數:31,代碼來源:actions.go

示例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
}
開發者ID:WH-Wang,項目名稱:megamd,代碼行數:57,代碼來源:actions.go

示例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
}
開發者ID:vijaykanthm28,項目名稱:gulp,代碼行數:10,代碼來源:provision.go

示例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
}
開發者ID:rajthilakmca,項目名稱:megamgulp,代碼行數:53,代碼來源:actions.go

示例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
}
開發者ID:rajthilakmca,項目名稱:megamgulp,代碼行數:56,代碼來源:actions.go

示例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
}
開發者ID:rajthilakmca,項目名稱:gulp,代碼行數:13,代碼來源:actions.go


注:本文中的github.com/megamsys/libgo/exec.OsExecutor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。