func Init(logPrefix string) error { // Once you run as root, you pretty much destroy the chances of a // non-privileged user starting the program correctly. if uid := os.Getuid(); uid == 0 { return fmt.Errorf("running this as root makes no sense") } if logPrefix != "" { logPrefix += " " } logPrefix += fmt.Sprintf("[%v] ", os.Getpid()) f, err := logfile.Open(*logfileName, *logFrequency, *logMaxSize, *logMaxFiles) if err != nil { return fmt.Errorf("unable to open logfile %s: %v", *logfileName, err) } relog.SetOutput(f) relog.SetPrefix(logPrefix) relog.SetLevel(relog.DEBUG) relog.HijackLog(nil) // FIXME(msolomon) Can't hijack with a logfile because the file descriptor // changes after every rotation. Might need to make the logfile more posix // friendly. //relog.HijackStdio(f, f) runtime.MemProfileRate = *memProfileRate gomaxprocs := os.Getenv("GOMAXPROCS") if gomaxprocs == "" { gomaxprocs = "1" } // Could report this in an expvar instead. relog.Info("GOMAXPROCS = %v", gomaxprocs) // We used to set this limit directly, but you pretty much have to // use a root account to allow increasing a limit reliably. Dropping // privileges is also tricky. The best strategy is to make a shell // script set up the limits as root and switch users before starting // the server. fdLimit := &syscall.Rlimit{} if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, fdLimit); err != nil { relog.Error("max-open-fds failed: %v", err) } else { // Could report this in an expvar instead. relog.Info("max-open-fds: %v", fdLimit.Cur) } return exportBinaryVersion() }
func main() { defer func() { if panicErr := recover(); panicErr != nil { relog.Fatal("panic: %v", tb.Errorf("%v", panicErr)) } }() flag.Parse() args := flag.Args() if len(args) != 0 { flag.Usage() os.Exit(1) } logLevel, err := relog.LogNameToLogLevel(*logLevel) if err != nil { relog.Fatal("%v", err) } relog.SetLevel(logLevel) if *fromTopo == "" || *toTopo == "" { relog.Fatal("Need both from and to topo") } fromTS := topo.GetServerByName(*fromTopo) toTS := topo.GetServerByName(*toTopo) if *doKeyspaces { topotools.CopyKeyspaces(fromTS, toTS) } if *doShards { topotools.CopyShards(fromTS, toTS, *deleteKeyspaceShards) } if *doTablets { topotools.CopyTablets(fromTS, toTS) } }