func UpstartCommand() *commander.Command { fs := flag.NewFlagSet("upstart", flag.ExitOnError) cwd, err := os.Getwd() if nil != err { glog.Fatal(err) } wd := fs.String("dir", cwd, "Directory of flashcache executable") user := fs.String("user", "flashcache", "User to run flashcache") group := fs.String("group", "flashcache", "Group to run flashcache") port := fs.Int("port", 16021, "Port to run flashcache on") bind := fs.String("bind", "127.0.0.1", "Address to which to bind webserver") return commander.NewCommand("upstart", "Output upstart script for flashcache", fs, func(args []string) error { return _upstartTemplate.Execute(os.Stdout, map[string]string{ "Dir": *wd, "User": *user, "Group": *group, "Port": fmt.Sprintf("%d", *port), "Bind": *bind, }) }) }
func WriteEnvCommand() *commander.Command { fs := flag.NewFlagSet("write-env", flag.ExitOnError) port := fs.Int("port", 16021, "Port on which flashcache runs") server := fs.String("server", "127.0.0.1", "Server location of flashcache (ip or fqdn)") return commander.NewCommand("write-env", "Write /etc/environment to set. FLASHCACHE_SERVER value", fs, func(args []string) error { return WriteEnvironment(*server, *port) }) }
func SetEnvCommand() *commander.Command { fs := flag.NewFlagSet("setenv", flag.ExitOnError) port := fs.Int("port", 16021, "Port on which flashcache runs") server := fs.String("server", "127.0.0.1", "Server location of flashcache (ip or fqdn)") return commander.NewCommand("setenv", "Return a script to set FlashCache environment values", fs, func(args []string) error { return SetEnvScript(os.Stdout, *server, *port) }) }
func WebCommand() *commander.Command { fs := flag.NewFlagSet("web", flag.ExitOnError) port := fs.Int("port", GetEnvPort(), "Port on which webserver should run") bind := fs.String("bind", "", "IP on which to bind webserver") return commander.NewCommand("web", "Run the cacheweb webserver", fs, func(args []string) error { http.HandleFunc("/__version", func(w http.ResponseWriter, r *http.Request) { js := json.NewEncoder(w) js.Encode(map[string]string{ "version": "1.0.0", }) }) http.HandleFunc("/__dump", TheCache.WebDump) http.HandleFunc("/", CacheWeb) glog.Infof("Starting flashcache webserver on port %d", *port) return http.ListenAndServe(fmt.Sprintf("%s:%d", *bind, *port), nil) }) }