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) }
// ServeRPC will deal with bson rpc serving func ServeRPC() { // rpc.HandleHTTP registers the default GOB handler at /_goRPC_ // and the debug RPC service at /debug/rpc (it displays a list // of registered services and their methods). if serviceMap["gob-vt"] { log.Infof("Registering GOB handler and /debug/rpc URL for vt port") rpc.HandleHTTP() } if serviceMap["gob-auth-vt"] { log.Infof("Registering GOB handler and /debug/rpcs URL for SASL vt port") rpcwrap.AuthenticatedServer.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath+"s") } // if we have an authentication config, we register the authenticated // bsonrpc services. if *authConfig != "" { if err := auth.LoadCredentials(*authConfig); err != nil { log.Fatalf("could not load authentication credentials, not starting rpc servers: %v", err) } bsonrpc.ServeAuthRPC() } // and register the regular bsonrpc too. bsonrpc.ServeRPC() }
// zkocc: a proxy for zk func main() { flag.Parse() if err := servenv.Init("zkocc"); err != nil { relog.Fatal("Error in servenv.Init: %v", err) } rpc.HandleHTTP() jsonrpc.ServeHTTP() jsonrpc.ServeRPC() bsonrpc.ServeHTTP() bsonrpc.ServeRPC() zk.RegisterZkReader(zkocc.NewZkReader(*resolveLocal, flag.Args())) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. umgmt.SetLameDuckPeriod(float32(*lameDuckPeriod)) umgmt.SetRebindDelay(float32(*rebindDelay)) umgmt.AddStartupCallback(func() { umgmt.StartHttpServer(fmt.Sprintf(":%v", *port)) }) relog.Info("started zkocc %v", *port) umgmtSocket := fmt.Sprintf("/tmp/zkocc-%08x-umgmt.sock", *port) if umgmtErr := umgmt.ListenAndServe(umgmtSocket); umgmtErr != nil { relog.Error("umgmt.ListenAndServe err: %v", umgmtErr) } relog.Info("done") }
// ServeRPC will deal with bson rpc serving func ServeRPC() { // rpc.HandleHTTP registers the default GOB handler at /_goRPC_ // and the debug RPC service at /debug/rpc (it displays a list // of registered services and their methods). if serviceMap["gob-vt"] { log.Infof("Registering GOB handler and /debug/rpc URL for vt port") rpc.HandleHTTP() } // and register the regular bsonrpc too. bsonrpc.ServeRPC() }
func ServeRPC() { rpc.HandleHTTP() if *authConfig != "" { if err := auth.LoadCredentials(*authConfig); err != nil { log.Fatalf("could not load authentication credentials, not starting rpc servers: %v", err) } bsonrpc.ServeAuthRPC() jsonrpc.ServeAuthRPC() } jsonrpc.ServeHTTP() jsonrpc.ServeRPC() bsonrpc.ServeHTTP() bsonrpc.ServeRPC() }
func main() { flag.Parse() servenv.Init("vt_binlog_server") binlogServer := new(BinlogServer) if *mycnfFile == "" { relog.Fatal("Please specify the path for mycnf file.") } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { relog.Fatal("Error reading mycnf file %v", *mycnfFile) } binlogServer.mycnf = mycnf binlogServer.dbname = strings.ToLower(strings.TrimSpace(*dbname)) binlogServer.blpStats = NewBlpStats() rpc.Register(binlogServer) rpcwrap.RegisterAuthenticated(binlogServer) //bsonrpc.ServeAuthRPC() rpc.HandleHTTP() bsonrpc.ServeHTTP() bsonrpc.ServeRPC() umgmt.SetLameDuckPeriod(30.0) umgmt.SetRebindDelay(0.01) umgmt.AddStartupCallback(func() { umgmt.StartHttpServer(fmt.Sprintf(":%v", *port)) }) umgmt.AddStartupCallback(func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) go func() { for sig := range c { umgmt.SigTermHandler(sig) } }() }) relog.Info("vt_binlog_server registered at port %v", *port) umgmtSocket := fmt.Sprintf("/tmp/vt_binlog_server-%08x-umgmt.sock", *port) if umgmtErr := umgmt.ListenAndServe(umgmtSocket); umgmtErr != nil { relog.Error("umgmt.ListenAndServe err: %v", umgmtErr) } relog.Info("done") }
func main() { flag.Parse() if err := servenv.Init("vtocc"); err != nil { relog.Fatal("Error in servenv.Init: %v", err) } if *queryLog != "" { if f, err := os.OpenFile(*queryLog, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644); err == nil { ts.QueryLogger = relog.New(f, "", relog.DEBUG) } else { relog.Fatal("Error opening file %v: %v", *queryLog, err) } } ts.SqlQueryLogger.ServeLogs("/debug/querylog") ts.TxLogger.ServeLogs("/debug/txlog") unmarshalFile(*configFile, &config) data, _ := json.MarshalIndent(config, "", " ") relog.Info("config: %s\n", data) unmarshalFile(*dbConfigFile, &dbconfig) relog.Info("dbconfig: %s\n", dbconfig) unmarshalFile(*overridesFile, &schemaOverrides) data, _ = json.MarshalIndent(schemaOverrides, "", " ") relog.Info("schemaOverrides: %s\n", data) ts.RegisterQueryService(config) qrs := loadCustomRules() ts.AllowQueries(dbconfig, schemaOverrides, qrs) rpc.HandleHTTP() // NOTE(szopa): Changing credentials requires a server // restart. if *authConfig != "" { if err := auth.LoadCredentials(*authConfig); err != nil { relog.Error("could not load authentication credentials, not starting rpc servers: %v", err) } serveAuthRPC() } serveRPC() relog.Info("started vtocc %v", *port) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. usefulLameDuckPeriod := float64(config.QueryTimeout + 1) if usefulLameDuckPeriod > *lameDuckPeriod { *lameDuckPeriod = usefulLameDuckPeriod relog.Info("readjusted -lame-duck-period to %f", *lameDuckPeriod) } umgmt.SetLameDuckPeriod(float32(*lameDuckPeriod)) umgmt.SetRebindDelay(float32(*rebindDelay)) umgmt.AddStartupCallback(func() { umgmt.StartHttpServer(fmt.Sprintf(":%v", *port)) }) umgmt.AddStartupCallback(func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) go func() { for sig := range c { umgmt.SigTermHandler(sig) } }() }) umgmt.AddCloseCallback(func() { ts.DisallowQueries(true) }) umgmtSocket := fmt.Sprintf("/tmp/vtocc-%08x-umgmt.sock", *port) if umgmtErr := umgmt.ListenAndServe(umgmtSocket); umgmtErr != nil { relog.Error("umgmt.ListenAndServe err: %v", umgmtErr) } relog.Info("done") }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() if err := servenv.Init("vttablet"); err != nil { relog.Fatal("Error in servenv.Init: %s", err) } tabletAlias := tabletParamToTabletAlias(*tabletPath) mycnf := readMycnf(tabletAlias.Uid) dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Warning("%s", err) } initQueryService(dbcfgs) initUpdateStreamService(mycnf) ts.RegisterCacheInvalidator() // depends on both query and updateStream err = vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile, *port, *securePort, *mycnfFile, *customrules, *overridesFile) // depends on both query and updateStream if err != nil { relog.Fatal("%s", err) } rpc.HandleHTTP() // NOTE(szopa): Changing credentials requires a server // restart. if *authConfig != "" { if err := auth.LoadCredentials(*authConfig); err != nil { relog.Error("could not load authentication credentials, not starting rpc servers: %v", err) } serveAuthRPC() } serveRPC() vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. umgmt.SetLameDuckPeriod(float32(*lameDuckPeriod)) umgmt.SetRebindDelay(float32(*rebindDelay)) umgmt.AddStartupCallback(func() { umgmt.StartHttpServer(fmt.Sprintf(":%v", *port)) if *securePort != 0 { relog.Info("listening on secure port %v", *securePort) umgmt.StartHttpsServer(fmt.Sprintf(":%v", *securePort), *cert, *key, *caCert) } }) umgmt.AddStartupCallback(func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) go func() { for sig := range c { umgmt.SigTermHandler(sig) } }() }) relog.Info("started vttablet %v", *port) umgmtSocket := fmt.Sprintf("/tmp/vttablet-%08x-umgmt.sock", *port) if umgmtErr := umgmt.ListenAndServe(umgmtSocket); umgmtErr != nil { relog.Error("umgmt.ListenAndServe err: %v", umgmtErr) } relog.Info("done") }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() if err := servenv.Init("vttablet"); err != nil { relog.Fatal("Error in servenv.Init: %s", err) } tabletAlias := tabletParamToTabletAlias(*tabletPath) mycnf := readMycnf(tabletAlias.Uid) dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Warning("%s", err) } dbcfgs.App.Memcache = *rowcache if err := jscfg.ReadJson(*overridesFile, &schemaOverrides); err != nil { relog.Warning("%s", err) } else { data, _ := json.MarshalIndent(schemaOverrides, "", " ") relog.Info("schemaOverrides: %s\n", data) } initQueryService(dbcfgs) initUpdateStreamService(mycnf) ts.RegisterCacheInvalidator() // depends on both query and updateStream err = initAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile) // depends on both query and updateStream if err != nil { relog.Fatal("%s", err) } rpc.HandleHTTP() // NOTE(szopa): Changing credentials requires a server // restart. if *authConfig != "" { if err := auth.LoadCredentials(*authConfig); err != nil { relog.Error("could not load authentication credentials, not starting rpc servers: %v", err) } serveAuthRPC() } serveRPC() // make a list of paths we can serve HTTP traffic from. // we don't resolve them here to real paths, as they might not exits yet snapshotDir := mysqlctl.SnapshotDir(tabletAlias.Uid) allowedPaths := []string{ path.Join(vtenv.VtDataRoot(), "data"), mysqlctl.TabletDir(tabletAlias.Uid), snapshotDir, mycnf.DataDir, mycnf.InnodbDataHomeDir, mycnf.InnodbLogGroupHomeDir, } // NOTE: trailing slash in pattern means we handle all paths with this prefix http.Handle(mysqlctl.SnapshotURLPath+"/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handleSnapshot(w, r, snapshotDir, allowedPaths) })) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. umgmt.SetLameDuckPeriod(float32(*lameDuckPeriod)) umgmt.SetRebindDelay(float32(*rebindDelay)) umgmt.AddStartupCallback(func() { umgmt.StartHttpServer(fmt.Sprintf(":%v", *port)) if *securePort != 0 { relog.Info("listening on secure port %v", *securePort) umgmt.StartHttpsServer(fmt.Sprintf(":%v", *securePort), *cert, *key, *caCert) } }) umgmt.AddStartupCallback(func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) go func() { for sig := range c { umgmt.SigTermHandler(sig) } }() }) relog.Info("started vttablet %v", *port) umgmtSocket := fmt.Sprintf("/tmp/vttablet-%08x-umgmt.sock", *port) if umgmtErr := umgmt.ListenAndServe(umgmtSocket); umgmtErr != nil { relog.Error("umgmt.ListenAndServe err: %v", umgmtErr) } relog.Info("done") }