Esempio n. 1
0
func generateServiceBasedCmd(s *Service, ai *access.Access, command []values.String) *exec.Cmd {
	logger := (*s).logger
	config := (*s).config
	executable := s.expandValue(ai, command[0].String())
	cmd := exec.Command(executable, getServiceBasedRunArgumentsFor(s, ai, command)...)
	cmd.Stdout = logger.Stdout()
	cmd.Stderr = logger.Stderr()
	cmd.SysProcAttr = s.createSysProcAttr()
	if !config.Directory.IsTrimmedEmpty() {
		cmd.Dir = s.expandValue(ai, config.Directory.String())
	}
	for key, value := range config.Environment {
		cmd.Env = append(cmd.Env, key+"="+value)
	}
	if ai.Type() == access.GenerateToEnvironment {
		cmd.Env = append(cmd.Env, "CTD_PEM="+string(ai.Pem()))
	} else {
		cmd.Env = append(cmd.Env, "CTD_PEM=")
	}
	if config.InheritEnvironment {
		cmd.Env = append(cmd.Env, os.Environ()...)
	}
	serviceHandleUsersFor(s, cmd)
	return cmd
}
Esempio n. 2
0
func (instance *Service) expandValue(ai *access.Access, in string) string {
	return os.Expand(in, func(key string) string {
		if value, ok := (*instance).config.Environment[key]; ok {
			return value
		} else if key == "CTD_PEM" {
			if ai.Type() == access.GenerateToEnvironment {
				return string(ai.Pem())
			}
			return ""
		}
		return os.Getenv(key)
	})
}