Example #1
0
func main() {

	flag.Parse()

	if *logArg != "stderr" {
		logSetup := utils.NewDefaultLogSetup(*logArg)
		logSetup.SetupLogging()
		go utils.ListenForLogSignal(logSetup)
	} else {
		log.SetFlags(log.LstdFlags | log.Lshortfile)
	}

	config := newshound.NewConfig()

	sess, err := config.MgoSession()
	if err != nil {
		log.Fatal(err)
	}
	defer sess.Close()

	if *reparse {
		if err := fetch.ReParse(config, sess); err != nil {
			log.Fatal(err)
		}
		return
	}

	go fetchMail(config, sess)

	mapReduce(sess)
}
Example #2
0
func main() {

	flag.Parse()

	if *logArg != "stderr" {
		logSetup := utils.NewDefaultLogSetup(*logArg)
		logSetup.SetupLogging()
		go utils.ListenForLogSignal(logSetup)
	} else {
		log.SetFlags(log.LstdFlags | log.Lshortfile)
	}

	config := newshound.NewConfig()

	d, err := bark.NewDistributor(config.NSQDAddr, config.NSQLAddr, config.BarkdChannel)
	if err != nil {
		log.Fatal(err)
	}

	// SLACK
	for _, slackAlert := range config.SlackAlerts {
		bark.AddSlackAlertBot(d, slackAlert.Key, slackAlert.Bot)
	}
	for _, slackEvent := range config.SlackEvents {
		bark.AddSlackEventBot(d, slackEvent.Key, slackEvent.Bot)
	}

	// TWITTER
	for _, twitterCreds := range config.Twitter {
		anaconda.SetConsumerKey(twitterCreds.ConsumerKey)
		anaconda.SetConsumerSecret(twitterCreds.ConsumerSecret)
		bark.AddTwitterAlertBot(d, twitterCreds.AccessToken, twitterCreds.AccessTokenSecret)
		bark.AddTwitterEventBot(d, twitterCreds.AccessToken, twitterCreds.AccessTokenSecret)
		bark.AddTwitterEventUpdateBot(d, twitterCreds.AccessToken, twitterCreds.AccessTokenSecret)
	}

	// WEBSOCKETS
	if config.WSPort != 0 {
		bark.AddWebSocketBarker(d, config.WSPort, true, true)
	}

	// WOOF
	quit := d.ListenAndBark()

	// wait for kill
	ch := make(chan os.Signal, 1)
	signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
	log.Printf("Received signal %s. Initiating stop.", <-ch)

	// signal stop and wait
	errs := make(chan error, 1)
	quit <- errs
	err = <-errs
	if err != nil {
		log.Fatal("shut down error: ", err)
	}
}
Example #3
0
func main() {
	logSetup := utils.NewDefaultLogSetup(serverLog)
	logSetup.SetupLogging()
	go utils.ListenForLogSignal(logSetup)

	router := mux.NewRouter()

	// add subway stuffs to server
	sconfig := NewConfig(subwayConfig)
	setupSubway(router, sconfig, subwayWeb, "subway.jprbnsn.com")
	setupSubway(router, sconfig, subwayWeb, "wheresthetrain.nyc")
	setupSubway(router, sconfig, subwayWeb, "www.wheresthetrain.nyc")
	setupSubway(router, sconfig, subwayWeb, "wtt.nyc")
	setupSubway(router, sconfig, subwayWeb, "www.wtt.nyc")
	setupSubway(router, sconfig, wheresLWeb, "wheresthel.com")
	setupSubway(router, sconfig, wheresLWeb, "www.wheresthel.com")

	// add subway stuffs to server
	// add the countdown
	countdownRouter := router.Host("countdown.jprbnsn.com").Subrouter()
	countdownRouter.PathPrefix("/").Handler(http.FileServer(http.Dir("/opt/jp/www/thecountdown")))

	// add wg4gl
	setupWG4GL(router, "wg4gl.com")
	setupWG4GL(router, "www.wg4gl.com")

	setupColin(router, "colinjhiggins.com")
	setupColin(router, "www.colinjhiggins.com")

	setupJP(router, "jprbnsn.com")
	setupJP(router, "www.jprbnsn.com")

	// newshound API setup
	nconfig := NewConfig(houndConfig)
	newshoundAPI := api.NewNewshoundAPI(nconfig.DBURL, nconfig.DBUser, nconfig.DBPassword)
	// add newshound subdomain to webserver
	newshoundRouter := router.Host("newshound.jprbnsn.com").Subrouter()
	// add newshound's API to the subdomain
	newshoundAPIRouter := newshoundRouter.PathPrefix(newshoundAPI.UrlPrefix()).Subrouter()
	newshoundAPI.Handle(newshoundAPIRouter)
	// add newshound UI to to the subdomain
	newshoundRouter.PathPrefix("/").Handler(http.FileServer(http.Dir(newshoundWeb)))

	// add newshound barkd websockets
	barkdRouter := router.Host("newshound.jprbnsn.com:8888").Subrouter()
	barkdURL, _ := url.Parse("http://127.0.0.1:8888")
	barkdRouter.PathPrefix("/").Handler(httputil.NewSingleHostReverseProxy(barkdURL))

	handler := web.AccessLogHandler(accessLog, router)

	log.Fatal(http.ListenAndServe(":80", handler))
}
Example #4
0
func main() {
	config := newshound.NewConfig()

	logSetup := utils.NewDefaultLogSetup(newshound.ServerLog)
	logSetup.SetupLogging()
	go utils.ListenForLogSignal(logSetup)

	router := mux.NewRouter()

	api := api.NewNewshoundAPI(config.DBURL, config.DBUser, config.DBPassword)
	apiRouter := router.PathPrefix(api.UrlPrefix()).Subrouter()
	api.Handle(apiRouter)

	staticRouter := router.PathPrefix("/").Subrouter()
	staticRouter.PathPrefix("/").Handler(http.FileServer(http.Dir(newshound.WebDir)))

	handler := web.AccessLogHandler(newshound.AccessLog, router)

	log.Fatal(http.ListenAndServe(":8080", handler))
}
Example #5
0
func main() {

	flag.Parse()

	if *exampleConfig {
		fmt.Print(getExampleConfig())
		return
	}

	if *conns <= 0 {
		*conns = 10
	}

	var srcInfo copycat.InboxInfo
	var dstInfos []copycat.InboxInfo

	if len(*configFile) == 0 {
		// put together info from input
		var err error
		srcInfo, err = copycat.NewInboxInfo(*srcId, *srcPw, *srcHost)
		errCheck(err, "Source Info")

		var dstInfo copycat.InboxInfo
		dstInfo, err = copycat.NewInboxInfo(*dstId, *dstPw, *dstHost)
		errCheck(err, "Destination Info")
		dstInfos = append(dstInfos, dstInfo)

	} else {
		//READ THE CONFIG FILE
		cFile, err := os.Open(*configFile)
		errCheck(err, "Config File")

		configBytes, err := ioutil.ReadAll(cFile)
		errCheck(err, "Config File")
		cFile.Close()

		var config copycat.Config
		err = json.Unmarshal(configBytes, &config)
		errCheck(err, "Config File")

		srcInfo = config.Source
		err = srcInfo.Validate()
		errCheck(err, "Source Creds")

		dstInfos = config.Dest
		for _, info := range dstInfos {
			err = info.Validate()
			errCheck(err, "Destination Creds")
		}
	}

	// check log flag, setup logger if set.
	if len(*logFile) > 0 {
		logger := utils.DefaultLogSetup{LogFile: *logFile}
		logger.SetupLogging()
		go utils.ListenForLogSignal(logger)
	}

start:
	cat, err := copycat.NewCopyCat(srcInfo, dstInfos, *conns, *sync, *idle)
	if err != nil {
		log.Printf("Problems creating new copycat: %s", err.Error())
	}

	if !*quicksync {
		*quickcount = 0
	}

	switch {
	case *idle:
		cat.Idle(*sync, *purge, *dbFile)
		// if idle ended, something's up. just restart.
		log.Printf("Idle unexpectedly quit. attempting to close conns...")
		cat.Close()
		log.Print("Conns closed. restarting process.")
		goto start
	case *sync:
		cat.Sync(*purge, *dbFile, *quickcount)
		cat.Close()
	}
}
Example #6
0
// AccessLogHandler return a http.Handler that wraps h and logs requests to out in
// Apache Combined Log Format...with an NYT twist (SRCIP instead of RemoteAddr if it exists).
//
// See http://httpd.apache.org/docs/2.2/logs.html#combined for a description of this format.
//
// AccessLogHandler always sets the ident field of the log to -
func AccessLogHandler(accessLogName string, h http.Handler) http.Handler {
	logHandler := accessLogHandler{utils.GetLogFileHandle(accessLogName), h, accessLogName}

	go utils.ListenForLogSignal(&logHandler)
	return &logHandler
}