Example #1
0
File: nsqd.go Project: RetVal/nsq
func (n *NSQD) Main() {
	var httpListener net.Listener
	var httpsListener net.Listener

	ctx := &context{n}

	n.waitGroup.Wrap(func() { n.lookupLoop() })

	tcpListener, err := net.Listen("tcp", n.tcpAddr.String())
	if err != nil {
		n.logf("FATAL: listen (%s) failed - %s", n.tcpAddr, err)
		os.Exit(1)
	}
	n.tcpListener = tcpListener
	tcpServer := &tcpServer{ctx: ctx}
	n.waitGroup.Wrap(func() {
		util.TCPServer(n.tcpListener, tcpServer, n.opts.Logger)
	})

	if n.tlsConfig != nil && n.httpsAddr != nil {
		httpsListener, err = tls.Listen("tcp", n.httpsAddr.String(), n.tlsConfig)
		if err != nil {
			n.logf("FATAL: listen (%s) failed - %s", n.httpsAddr, err)
			os.Exit(1)
		}
		n.httpsListener = httpsListener
		httpsServer := &httpServer{
			ctx:         ctx,
			tlsEnabled:  true,
			tlsRequired: true,
		}
		n.waitGroup.Wrap(func() {
			util.HTTPServer(n.httpsListener, httpsServer, n.opts.Logger, "HTTPS")
		})
	}
	httpListener, err = net.Listen("tcp", n.httpAddr.String())
	if err != nil {
		n.logf("FATAL: listen (%s) failed - %s", n.httpAddr, err)
		os.Exit(1)
	}
	n.httpListener = httpListener
	httpServer := &httpServer{
		ctx:         ctx,
		tlsEnabled:  false,
		tlsRequired: n.opts.TLSRequired,
	}
	n.waitGroup.Wrap(func() {
		util.HTTPServer(n.httpListener, httpServer, n.opts.Logger, "HTTP")
	})

	if n.opts.StatsdAddress != "" {
		n.waitGroup.Wrap(func() { n.statsdLoop() })
	}
}
Example #2
0
func (n *NSQD) Main() {
	var httpListener net.Listener
	var httpsListener net.Listener

	context := &context{n}

	if n.options.TLSClientAuthPolicy != "" {
		n.options.TLSRequired = true
	}

	if n.tlsConfig == nil && n.options.TLSRequired {
		log.Fatalf("FATAL: cannot require TLS client connections without TLS key and cert")
	}

	n.waitGroup.Wrap(func() { n.lookupLoop() })

	tcpListener, err := net.Listen("tcp", n.tcpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", n.tcpAddr, err.Error())
	}
	n.tcpListener = tcpListener
	tcpServer := &tcpServer{context: context}
	n.waitGroup.Wrap(func() { util.TCPServer(n.tcpListener, tcpServer) })

	if n.tlsConfig != nil && n.httpsAddr != nil {
		httpsListener, err = tls.Listen("tcp", n.httpsAddr.String(), n.tlsConfig)
		if err != nil {
			log.Fatalf("FATAL: listen (%s) failed - %s", n.httpsAddr, err.Error())
		}
		n.httpsListener = httpsListener
		httpsServer := &httpServer{
			context:     context,
			tlsEnabled:  true,
			tlsRequired: true,
		}
		n.waitGroup.Wrap(func() { util.HTTPServer(n.httpsListener, httpsServer, "HTTPS") })
	}
	httpListener, err = net.Listen("tcp", n.httpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", n.httpAddr, err.Error())
	}
	n.httpListener = httpListener
	httpServer := &httpServer{
		context:     context,
		tlsEnabled:  false,
		tlsRequired: n.options.TLSRequired,
	}
	n.waitGroup.Wrap(func() { util.HTTPServer(n.httpListener, httpServer, "HTTP") })

	if n.options.StatsdAddress != "" {
		n.waitGroup.Wrap(func() { n.statsdLoop() })
	}
}
Example #3
0
File: nsqd.go Project: hzrandd/nsq
func (n *NSQD) Main() {
	context := &context{n}

	n.waitGroup.Wrap(func() { n.lookupLoop() })

	tcpListener, err := net.Listen("tcp", n.tcpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", n.tcpAddr, err.Error())
	}
	n.tcpListener = tcpListener
	tcpServer := &tcpServer{context: context}
	n.waitGroup.Wrap(func() { util.TCPServer(n.tcpListener, tcpServer) })

	httpListener, err := net.Listen("tcp", n.httpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", n.httpAddr, err.Error())
	}
	n.httpListener = httpListener
	httpServer := &httpServer{context: context}
	n.waitGroup.Wrap(func() { util.HTTPServer(n.httpListener, httpServer) })

	if n.options.StatsdAddress != "" {
		n.waitGroup.Wrap(func() { n.statsdLoop() })
	}
}
Example #4
0
func (l *NSQLookupd) Main() {
	ctx := &Context{l}

	tcpListener, err := net.Listen("tcp", l.tcpAddr.String())
	if err != nil {
		l.logf("FATAL: listen (%s) failed - %s", l.tcpAddr, err)
		os.Exit(1)
	}
	l.tcpListener = tcpListener
	tcpServer := &tcpServer{ctx: ctx}
	l.waitGroup.Wrap(func() {
		util.TCPServer(tcpListener, tcpServer, l.opts.Logger)
	})

	httpListener, err := net.Listen("tcp", l.httpAddr.String())
	if err != nil {
		l.logf("FATAL: listen (%s) failed - %s", l.httpAddr, err)
		os.Exit(1)
	}
	l.httpListener = httpListener
	httpServer := &httpServer{ctx: ctx}
	l.waitGroup.Wrap(func() {
		util.HTTPServer(httpListener, httpServer, l.opts.Logger, "HTTP")
	})
}
Example #5
0
func (n *NSQAdmin) Main() {
	httpListener, err := net.Listen("tcp", n.httpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", n.httpAddr, err.Error())
	}
	n.httpListener = httpListener
	httpServer := NewHTTPServer(&Context{n})
	n.waitGroup.Wrap(func() { util.HTTPServer(n.httpListener, httpServer, "HTTP") })
	n.waitGroup.Wrap(func() { n.handleAdminActions() })
}
Example #6
0
func (s *ConsServer) Main() {
	httpListener, err := net.Listen("tcp", s.opts.HttpAddr)
	if err != nil {
		log.Fatalf("ERR: listen (%s) failed - %s", s.opts.HttpAddr, err.Error())
	}
	s.httpListener = httpListener
	httpServer := &httpServer{context: &Context{s}}
	s.waitGroup.Wrap(func() { util.HTTPServer(s.httpListener, httpServer, "HTTP") })

	cb := func() {
		s.loadConf()

		ticker := time.NewTicker(time.Minute * 15)
		ticker2 := time.NewTicker(time.Minute)

		for {
			select {
			case <-ticker.C:
				s.reloadJson()

			case <-ticker2.C:
				s.updateReader(s.dbpool.InputChan)

			case <-s.dbpool.FailChan:
				s.Stop()
				log.Fatal("Fatal: pool notwork, server exit")

			case <-s.quit:
				goto END
			}
		}

	END:
		log.Println("INF: server quit loop")
		s.Stop()

		if s.httpListener != nil {
			s.httpListener.Close()
		}
	}

	log.Println("INF: server run")
	s.waitGroup.Wrap(cb)

}
Example #7
0
func (l *NSQLookupd) Main() {
	context := &Context{l}

	tcpListener, err := net.Listen("tcp", l.tcpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", l.tcpAddr, err.Error())
	}
	l.tcpListener = tcpListener
	tcpServer := &tcpServer{context: context}
	l.waitGroup.Wrap(func() { util.TCPServer(tcpListener, tcpServer) })

	httpListener, err := net.Listen("tcp", l.httpAddr.String())
	if err != nil {
		log.Fatalf("FATAL: listen (%s) failed - %s", l.httpAddr, err.Error())
	}
	l.httpListener = httpListener
	httpServer := &httpServer{context: context}
	l.waitGroup.Wrap(func() { util.HTTPServer(httpListener, httpServer, "HTTP") })
}