コード例 #1
0
ファイル: runtime_config.go プロジェクト: WeiZhang555/oct
/*
type Hooks struct {
	Prestart []Hook `optional`
	Poststop []Hook `optional`
}
*/
func HooksFrom(image schema.ImageManifest, msgs []string) (specs.Hooks, []string) {
	var hs specs.Hooks
	for index := 0; index < len(image.App.EventHandlers); index++ {
		var h specs.Hook
		eh := image.App.EventHandlers[index]
		if len(eh.Exec) == 0 {
			continue
		}
		for e_index := 0; e_index < len(eh.Exec); e_index++ {
			if e_index == 0 {
				h.Path = eh.Exec[0]
			} else {
				h.Args = append(h.Args, eh.Exec[e_index])
			}
		}
		switch eh.Name {
		case "pre-start":
			hs.Prestart = append(hs.Prestart, h)
			break
		case "post-stop":
			hs.Poststop = append(hs.Poststop, h)
			break
		}
	}
	return hs, msgs
}
コード例 #2
0
ファイル: main.go プロジェクト: kohlerm/riddler
func (s stringSlice) ParseHooks() (hooks specs.Hooks, err error) {
	for _, v := range s {
		parts := strings.SplitN(v, ":", 2)
		if len(parts) <= 1 {
			return hooks, fmt.Errorf("parsing %s as hook_name:exec failed", v)
		}
		cmd := strings.Split(parts[1], " ")
		exec, err := exec.LookPath(cmd[0])
		if err != nil {
			return hooks, fmt.Errorf("looking up exec path for %s failed: %v", cmd[0], err)
		}
		hook := specs.Hook{
			Path: exec,
		}
		if len(cmd) > 1 {
			hook.Args = cmd[:1]
		}
		switch parts[0] {
		case "prestart":
			hooks.Prestart = append(hooks.Prestart, hook)
		case "poststart":
			hooks.Poststart = append(hooks.Poststart, hook)
		case "poststop":
			hooks.Poststop = append(hooks.Poststop, hook)
		default:
			return hooks, fmt.Errorf("%s is not a valid hook, try 'prestart', 'poststart', or 'poststop'", parts[0])
		}
	}
	return hooks, nil
}