func main() { for idx := range os.Args { arg := os.Args[idx] if strings.HasPrefix(arg, "--h") || strings.HasPrefix(arg, "-h") { fmt.Fprintf(os.Stderr, USAGE) os.Exit(0) } } cnf := common.LoadApplicationConfig() common.InstallSignalHandlers(cnf) lg := common.NewLogger("main", cnf) defer lg.Close() store, err := CreateDataStore(cnf, nil) if err != nil { lg.Errorf("Error creating datastore: %s\n", err.Error()) os.Exit(1) } var rsv *RestServer rsv, err = CreateRestServer(cnf, store) if err != nil { lg.Errorf("Error creating REST server: %s\n", err.Error()) os.Exit(1) } var hsv *HrpcServer if cnf.Get(conf.HTRACE_HRPC_ADDRESS) != "" { hsv, err = CreateHrpcServer(cnf, store) if err != nil { lg.Errorf("Error creating HRPC server: %s\n", err.Error()) os.Exit(1) } } else { lg.Infof("Not starting HRPC server because no value was given for %s.\n", conf.HTRACE_HRPC_ADDRESS) } naddr := cnf.Get(conf.HTRACE_STARTUP_NOTIFICATION_ADDRESS) if naddr != "" { notif := StartupNotification{ HttpAddr: rsv.Addr().String(), ProcessId: os.Getpid(), } if hsv != nil { notif.HrpcAddr = hsv.Addr().String() } err = sendStartupNotification(naddr, ¬if) if err != nil { fmt.Fprintf(os.Stderr, "Failed to send startup notification: "+ "%s\n", err.Error()) os.Exit(1) } } for { time.Sleep(time.Duration(10) * time.Hour) } }
func main() { for idx := range os.Args { arg := os.Args[idx] if strings.HasPrefix(arg, "--h") || strings.HasPrefix(arg, "-h") { fmt.Fprintf(os.Stderr, USAGE) os.Exit(0) } } // Load the htraced configuration. cnf, cnfLog := conf.LoadApplicationConfig("htraced.") // Open the HTTP port. // We want to do this first, before initializing the datastore or setting up // logging. That way, if someone accidentally starts two daemons with the // same config file, the second invocation will exit with a "port in use" // error rather than potentially disrupting the first invocation. rstListener, listenErr := net.Listen("tcp", cnf.Get(conf.HTRACE_WEB_ADDRESS)) if listenErr != nil { fmt.Fprintf(os.Stderr, "Error opening HTTP port: %s\n", listenErr.Error()) os.Exit(1) } // Print out the startup banner and information about the daemon // configuration. lg := common.NewLogger("main", cnf) defer lg.Close() lg.Infof("*** Starting htraced %s [%s]***\n", RELEASE_VERSION, GIT_VERSION) scanner := bufio.NewScanner(cnfLog) for scanner.Scan() { lg.Infof(scanner.Text() + "\n") } common.InstallSignalHandlers(cnf) if runtime.GOMAXPROCS(0) == 1 { ncpu := runtime.NumCPU() runtime.GOMAXPROCS(ncpu) lg.Infof("setting GOMAXPROCS=%d\n", ncpu) } else { lg.Infof("GOMAXPROCS=%d\n", runtime.GOMAXPROCS(0)) } lg.Infof("leveldb version=%d.%d\n", levigo.GetLevelDBMajorVersion(), levigo.GetLevelDBMinorVersion()) // Initialize the datastore. store, err := CreateDataStore(cnf, nil) if err != nil { lg.Errorf("Error creating datastore: %s\n", err.Error()) os.Exit(1) } var rsv *RestServer rsv, err = CreateRestServer(cnf, store, rstListener) if err != nil { lg.Errorf("Error creating REST server: %s\n", err.Error()) os.Exit(1) } var hsv *HrpcServer if cnf.Get(conf.HTRACE_HRPC_ADDRESS) != "" { hsv, err = CreateHrpcServer(cnf, store, nil) if err != nil { lg.Errorf("Error creating HRPC server: %s\n", err.Error()) os.Exit(1) } } else { lg.Infof("Not starting HRPC server because no value was given for %s.\n", conf.HTRACE_HRPC_ADDRESS) } naddr := cnf.Get(conf.HTRACE_STARTUP_NOTIFICATION_ADDRESS) if naddr != "" { notif := StartupNotification{ HttpAddr: rsv.Addr().String(), ProcessId: os.Getpid(), } if hsv != nil { notif.HrpcAddr = hsv.Addr().String() } err = sendStartupNotification(naddr, ¬if) if err != nil { fmt.Fprintf(os.Stderr, "Failed to send startup notification: "+ "%s\n", err.Error()) os.Exit(1) } } for { time.Sleep(time.Duration(10) * time.Hour) } }