Example #1
0
func mustGetInt(yaml *simpleyaml.Yaml, key string) int {
	if rawVal := yaml.Get(key); isPresent(rawVal) {
		if val, err := rawVal.Int(); err != nil {
			panic(fmt.Sprintf("%s is not integer", key))
		} else {
			return val
		}
	}

	return 0
}
Example #2
0
func parseCommands(yaml *simpleyaml.Yaml, commands map[interface{}]interface{}) []Service {
	commonOptions := getServiceOptions(yaml)
	services := make([]Service, 0, len(commands))

	for key, _ := range commands {
		name := toString(key)
		commandYaml := yaml.GetPath("commands", name)
		cmd, _ := commandYaml.Get("command").String()

		service := Service{
			Name:    name,
			Cmd:     cmd,
			Options: getServiceOptions(commandYaml),
		}
		mergo.Merge(&service.Options, commonOptions)

		services = append(services, service)
	}

	return services
}
Example #3
0
func getServiceOptions(yaml *simpleyaml.Yaml) ServiceOptions {
	options := ServiceOptions{}

	options.WorkingDirectory, _ = yaml.Get("working_directory").String()
	options.User, _ = yaml.Get("user").String()
	options.Group, _ = yaml.Get("group").String()
	options.KillTimeout = mustGetInt(yaml, "kill_timeout")
	options.LogPath, _ = yaml.Get("log").String()
	options.Count = mustGetInt(yaml, "count")

	if value, err := yaml.Get("env").Map(); err == nil {
		options.Env = toStringMap(value)
	}

	if value := yaml.Get("respawn"); isPresent(value) {
		count := mustGetInt(value, "count")
		interval := mustGetInt(value, "interval")
		options.Respawn = Respawn{Count: count, Interval: interval}
	}

	return options
}