Esempio n. 1
0
func ExampleSetup(t *testing.T) {
	// make a config var to hold some flags
	var Config struct {
		Value int           `default:"20" usage:"this is some value"`
		Time  time.Duration `default:"10s" usage:"some duration"`
		What  string        `default:"such a string" usage:"quite the string"`
	}

	// this creates flags with names
	//     prefix.value
	//     prefix.time
	//     prefix.what
	utils.Setup("prefix", &Config)

	// this loads the flags into config. flagfile automatically adds a flag
	// named flagfile, which when specified will load the key/value pairs in
	// that file as if they were specified on the command line.
	flagfile.Load()
}
Esempio n. 2
0
func main() {
	flagfile.Load()
	if *cgroupPath == "" || len(flag.Args()) == 0 {
		fmt.Printf("usage: %s --cgroup <path> -- <subprocess> [args...]\n",
			os.Args[0])
		os.Exit(1)
	}

	panic(watch.NewWatcher(*cgroupPath).Watch(func(count int64) {
		log.Printf("%d ooms detected, running %v %d times",
			count, flag.Args(), count)

		for i := int64(0); i < count; i++ {
			cmd := exec.Command(flag.Arg(0), flag.Args()[1:]...)
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			err := cmd.Run()
			if err != nil {
				log.Printf("failed running %v: %s", flag.Args(), err)
			}
		}
	}))
}