func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() relog.Info("started vtaction %v", os.Args) rpc.HandleHTTP() jsonrpc.ServeHTTP() jsonrpc.ServeRPC() bsonrpc.ServeHTTP() bsonrpc.ServeRPC() logFile, err := os.OpenFile(*logFilename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666) if err != nil { relog.Fatal("Can't open log file: %v", err) } relog.SetOutput(logFile) relog.SetPrefix(fmt.Sprintf("vtaction [%v] ", os.Getpid())) if err := relog.SetLevelByName(*logLevel); err != nil { relog.Fatal("%v", err) } relog.HijackLog(nil) relog.HijackStdio(logFile, logFile) mycnf, mycnfErr := mysqlctl.ReadMycnf(*mycnfFile) if mycnfErr != nil { relog.Fatal("mycnf read failed: %v", mycnfErr) } relog.Debug("mycnf: %v", jscfg.ToJson(mycnf)) dbcfgs, cfErr := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Fatal("%s", cfErr) } mysqld := mysqlctl.NewMysqld(mycnf, dbcfgs.Dba, dbcfgs.Repl) topoServer := topo.GetServer() defer topo.CloseServers() actor := tabletmanager.NewTabletActor(mysqld, topoServer) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. bindAddr := fmt.Sprintf(":%v", *port) httpServer := &http.Server{Addr: bindAddr} go func() { if err := httpServer.ListenAndServe(); err != nil { relog.Error("httpServer.ListenAndServe err: %v", err) } }() actionErr := actor.HandleAction(*actionNode, *action, *actionGuid, *force) if actionErr != nil { relog.Fatal("action error: %v", actionErr) } relog.Info("finished vtaction %v", os.Args) }
func main() { flag.Parse() args := flag.Args() if len(args) == 0 { flag.Usage() os.Exit(1) } relog.SetPrefix("zkctl ") if err := relog.SetLevelByName(*logLevel); err != nil { log.Fatal(err) } zkConfig := zkctl.MakeZkConfigFromString(*zkCfg, uint32(*myId)) zkd := zkctl.NewZkd(zkConfig) action := flag.Arg(0) var err error switch action { case "init": err = zkd.Init() case "shutdown": err = zkd.Shutdown() case "start": err = zkd.Start() case "teardown": err = zkd.Teardown() default: log.Fatalf("invalid action: %v", action) } if err != nil { log.Fatalf("failed %v: %v", action, err) } }
func main() { flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [global parameters] command [command parameters]\n", os.Args[0]) fmt.Fprintf(os.Stderr, "\nThe global optional parameters are:\n") flag.PrintDefaults() fmt.Fprintf(os.Stderr, "\nThe commands are listed below. Use '%s <command> -h' for more help.\n\n", os.Args[0]) for _, cmd := range commands { fmt.Fprintf(os.Stderr, " %s", cmd.name) if cmd.params != "" { fmt.Fprintf(os.Stderr, " %s", cmd.params) } fmt.Fprintf(os.Stderr, "\n") } fmt.Fprintf(os.Stderr, "\n") } dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() if err := relog.SetLevelByName(*logLevel); err != nil { relog.Fatal("%v", err) } tabletAddr = fmt.Sprintf("%v:%v", "localhost", *port) mycnf := mysqlctl.NewMycnf(uint32(*tabletUid), *mysqlPort, mysqlctl.VtReplParams{}) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Fatal("%v", err) } mysqld := mysqlctl.NewMysqld(mycnf, dbcfgs.Dba, dbcfgs.Repl) action := flag.Arg(0) for _, cmd := range commands { if cmd.name == action { subFlags := flag.NewFlagSet(action, flag.ExitOnError) subFlags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s %s %s\n\n", os.Args[0], cmd.name, cmd.params) fmt.Fprintf(os.Stderr, "%s\n\n", cmd.help) subFlags.PrintDefaults() } cmd.method(mysqld, subFlags, flag.Args()[1:]) return } } relog.Fatal("invalid action: %v", action) }