func main() { flag.Parse() // Create a new Raven client var rc *raven.Client if *ravenDSN != "" { h, err := os.Hostname() if err != nil { log.Fatal(err) } rc, err = raven.NewClient(*ravenDSN, map[string]string{ "hostname": h, }) if err != nil { log.Fatal(err) } } defer func() { var packet *raven.Packet p := recover() switch rval := p.(type) { case nil: return case error: packet = raven.NewPacket(rval.Error(), raven.NewException(rval, raven.NewStacktrace(2, 3, nil))) default: rvalStr := fmt.Sprint(rval) packet = raven.NewPacket(rvalStr, raven.NewException(errors.New(rvalStr), raven.NewStacktrace(2, 3, nil))) } _, ch := rc.Capture(packet, nil) <-ch panic(p) }() config := &shared.Flags{ EtcdAddress: *etcdAddress, EtcdCAFile: *etcdCAFile, EtcdCertFile: *etcdCertFile, EtcdKeyFile: *etcdKeyFile, EtcdPath: *etcdPath, BindAddress: *bindAddress, WelcomeMessage: *welcomeMessage, Hostname: *hostname, LogFormatterType: *logFormatterType, ForceColors: *forceColors, RethinkAddress: *rethinkdbAddress, RethinkKey: *rethinkdbKey, RethinkDatabase: *rethinkdbDatabase, NSQDAddress: *nsqdAddress, LookupdAddress: *lookupdAddress, SMTPAddress: *smtpAddress, SpamdAddress: *spamdAddress, DKIMKey: *dkimKey, DKIMSelector: *dkimSelector, } h := handler.PrepareHandler(config) server := &smtpd.Server{ WelcomeMessage: *welcomeMessage, Handler: h, } outbound.StartQueue(config) server.ListenAndServe(*bindAddress) }
func main() { // Parse the flags flag.Parse() // Put config into the environment package env.Config = &env.Flags{ BindAddress: *bindAddress, APIVersion: *apiVersion, LogFormatterType: *logFormatterType, ForceColors: *forceColors, EmailDomain: *emailDomain, SessionDuration: *sessionDuration, RedisAddress: *redisAddress, RedisDatabase: *redisDatabase, RedisPassword: *redisPassword, RethinkDBAddress: *rethinkdbAddress, RethinkDBKey: *rethinkdbKey, RethinkDBDatabase: *rethinkdbDatabase, NSQdAddress: *nsqdAddress, LookupdAddress: *lookupdAddress, YubiCloudID: *yubiCloudID, YubiCloudKey: *yubiCloudKey, SlackURL: *slackURL, SlackLevels: *slackLevels, SlackChannel: *slackChannel, SlackIcon: *slackIcon, SlackUsername: *slackUsername, BloomFilter: *bloomFilter, BloomCount: *bloomCount, RavenDSN: *ravenDSN, } // Generate a mux mux := setup.PrepareMux(env.Config) // Make the mux handle every request http.Handle("/", mux) // Log that we're starting the server env.Log.WithFields(logrus.Fields{ "address": env.Config.BindAddress, }).Info("Starting the HTTP server") // Initialize the goroutine listening to signals passed to the app graceful.HandleSignals() // Pre-graceful shutdown event graceful.PreHook(func() { env.Log.Info("Received a singnal, stopping the application") }) // Post-shutdown event graceful.PostHook(func() { env.Log.Info("Stopped the application") }) // Listen to the passed address listener, err := net.Listen("tcp", env.Config.BindAddress) if err != nil { env.Log.WithFields(logrus.Fields{ "error": err, "address": *bindAddress, }).Fatal("Cannot set up a TCP listener") } // Start the listening err = graceful.Serve(listener, http.DefaultServeMux) if err != nil { // Don't use .Fatal! We need the code to shut down properly. env.Log.Error(err) } // If code reaches this place, it means that it was forcefully closed. // Wait until open connections close. graceful.Wait() }