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() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() servenv.Init() if *mycnfFile == "" { log.Fatalf("Please specify the path for mycnf file.") } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("Error reading mycnf file %v", *mycnfFile) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { log.Warning(err) } mysqld := mysqlctl.NewMysqld(mycnf, dbcfgs.Dba, dbcfgs.Repl) binlogServer := mysqlctl.NewBinlogServer(mysqld) mysqlctl.EnableBinlogServerService(binlogServer, *dbname) proto.RegisterBinlogServer(binlogServer) rpcwrap.RegisterAuthenticated(binlogServer) servenv.OnClose(func() { mysqlctl.DisableBinlogServerService(binlogServer) }) servenv.Run(*port) }
func readMycnf(tabletId uint32) *mysqlctl.Mycnf { if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletId) } mycnf, mycnfErr := mysqlctl.ReadMycnf(*mycnfFile) if mycnfErr != nil { relog.Fatal("mycnf read failed: %v", mycnfErr) } return mycnf }
func main() { dbconfigs.RegisterFlags() flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Fatalf("vttablet doesn't take any positional arguments") } servenv.Init() if *tabletPath == "" { log.Fatalf("tabletPath required") } tabletAlias := tabletParamToTabletAlias(*tabletPath) if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid) } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile) if err != nil { log.Warning(err) } dbcfgs.App.EnableRowcache = *enableRowcache tabletserver.InitQueryService() binlog.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. agent, err = tabletmanager.NewActionAgent(tabletAlias, dbcfgs, mycnf, *servenv.Port, *servenv.SecurePort, *overridesFile) if err != nil { log.Fatal(err) } tabletmanager.HttpHandleSnapshots(mycnf, tabletAlias.Uid) servenv.OnTerm(func() { tabletserver.DisallowQueries() binlog.DisableUpdateStreamService() agent.Stop() }) servenv.OnClose(func() { // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.Run() }
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() { dbconfigs.RegisterCommonFlags() flag.Parse() servenv.Init() defer servenv.Close() log.Infof("started vtaction %v", os.Args) servenv.ServeRPC() mycnf, mycnfErr := mysqlctl.ReadMycnf(*mycnfFile) if mycnfErr != nil { log.Fatalf("mycnf read failed: %v", mycnfErr) } log.V(6).Infof("mycnf: %v", jscfg.ToJson(mycnf)) dbcfgs, cfErr := dbconfigs.Init(mycnf.SocketFile) if cfErr != nil { log.Fatalf("%s", cfErr) } mysqld := mysqlctl.NewMysqld(mycnf, &dbcfgs.Dba, &dbcfgs.Repl) topoServer := topo.GetServer() defer topo.CloseServers() actor := tabletmanager.NewTabletActor(mysqld, mysqld, topoServer, topo.TabletAlias{}) // 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 { log.Errorf("httpServer.ListenAndServe err: %v", err) } }() actionErr := actor.HandleAction(*actionNode, *action, *actionGuid, *force) if actionErr != nil { log.Fatalf("action error: %v", actionErr) } log.Infof("finished vtaction %v", os.Args) }
func main() { dbconfigs.RegisterFlags() flag.Parse() servenv.Init() if *tabletPath == "" { log.Fatalf("tabletPath required") } tabletAlias := vttablet.TabletParamToTabletAlias(*tabletPath) if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid) } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile) if err != nil { log.Warning(err) } dbcfgs.App.EnableRowcache = *enableRowcache ts.InitQueryService() binlog.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. agent, err = vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *servenv.Port, *servenv.SecurePort, *overridesFile) if err != nil { log.Fatal(err) } vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) servenv.OnClose(func() { time.Sleep(5 * time.Millisecond) ts.DisallowQueries() binlog.DisableUpdateStreamService() topo.CloseServers() agent.Stop() }) servenv.Run() }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() servenv.Init() tabletAlias := vttablet.TabletParamToTabletAlias(*tabletPath) if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid) } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { log.Warning(err) } ts.InitQueryService() mysqlctl.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. ts.RegisterCacheInvalidator() // Depends on both query and updateStream. if err := vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile, *port, *securePort, *mycnfFile, *overridesFile); err != nil { log.Fatal(err) } vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) servenv.OnClose(func() { time.Sleep(5 * time.Millisecond) ts.DisallowQueries() mysqlctl.DisableUpdateStreamService() topo.CloseServers() vttablet.CloseAgent() }) servenv.RunSecure(*port, *securePort, *cert, *key, *caCert) }
func main() { flag.Parse() servenv.Init() defer servenv.Close() if *mycnfFile == "" { log.Fatalf("Please specify the path for mycnf file.") } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("Error reading mycnf file %v", *mycnfFile) } binlogServer := mysqlctl.NewBinlogServer(mycnf) mysqlctl.EnableBinlogServerService(binlogServer, *dbname) proto.RegisterBinlogServer(binlogServer) rpcwrap.RegisterAuthenticated(binlogServer) servenv.ServeRPC() proc.ListenAndServe(fmt.Sprintf("%v", *port)) mysqlctl.DisableBinlogServerService(binlogServer) }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() servenv.Init() defer servenv.Close() tabletAlias := vttablet.TabletParamToTabletAlias(*tabletPath) if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid) } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { log.Warning(err) } ts.InitQueryService() mysqlctl.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. ts.RegisterCacheInvalidator() // Depends on both query and updateStream. if err := vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile, *port, *securePort, *mycnfFile, *overridesFile); err != nil { log.Fatal(err) } servenv.ServeRPC() vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) l, err := proc.Listen(fmt.Sprintf("%v", *port)) if err != nil { log.Fatal(err) } go http.Serve(l, nil) if *securePort != 0 { log.Infof("listening on secure port %v", *securePort) vttablet.SecureServe(fmt.Sprintf(":%d", *securePort), *cert, *key, *caCert) } log.Infof("started vttablet %v", *port) s := proc.Wait() // A SIGUSR1 means that we're restarting if s == syscall.SIGUSR1 { // Give some time for the other process // to pick up the listeners log.Info("Exiting on SIGUSR1") time.Sleep(5 * time.Millisecond) ts.DisallowQueries(true) } else { log.Info("Exiting on SIGTERM") ts.DisallowQueries(false) } mysqlctl.DisableUpdateStreamService() topo.CloseServers() vttablet.CloseAgent() }