Example #1
0
func (o *ServiceOperation) Run(vars map[string]string) error {
	name := util.ParseString(o.Name, vars)
	action := util.ParseString(o.Action, vars)

	//	Switch method from service manager(SystemV init/systemd)
	var cmd *exec.Cmd
	switch config.ServiceManager {
	case "init":
		cmd = exec.Command("/sbin/service", name, action)
	case "systemd":
		cmd = exec.Command("/sbin/systemctl", action, name)
	default:
		return errors.New(fmt.Sprintf("Unknown service manager(%s)", config.ServiceManager))
	}

	out, err := cmd.CombinedOutput()
	log.Debug(string(out))
	return err
}
Example #2
0
//	Set environment variables from environment node in task.yml
func (s *Schedule) setEnvironmentVariables() {
	r := regexp.MustCompile(`\$[a-zA-Z0-9_-]+`)
	for k, v := range s.Environments {
		v = r.ReplaceAllStringFunc(v, func(s string) string {
			return os.Getenv(s[1:len(s)])
		})
		v = util.ParseString(v, s.Variables)
		os.Setenv(k, v)
		log.Info(fmt.Sprintf("Set environment(%s): %s", k, v))
	}
}
Example #3
0
func (o *ExecuteOperation) Run(vars map[string]string) error {
	cmd := &exec.Cmd{}
	cmd.Dir = filepath.Dir(o.path)
	if o.File != "" {
		//	Execute target file with arguuments
		file := util.ParseString(o.File, vars)
		cmd.Path = file
		cmd.Args = append([]string{file}, o.Arguments...)
	} else {
		//	Execute script in the shell
		cmd.Path = "/bin/sh"
		s := util.ParseString(o.Script, vars)
		cmd.Stdin = strings.NewReader(s)
	}
	out, err := cmd.CombinedOutput()

	//	Output STDOUT if output flag in task.yml is true
	if o.Output {
		log.Info(string(out))
	}
	return err
}
Example #4
0
func (o *EchoOperation) Run(vars map[string]string) error {
	log.Info("echo: " + util.ParseString(o.message, vars))
	return nil
}