Exemplo n.º 1
0
func (p *program) Start(s service.Service) error {
	flagSet.Parse(os.Args[1:])

	if *showVersion {
		fmt.Println(util.Version("nsqlookupd"))
		os.Exit(0)
		return nil
	}

	var cfg map[string]interface{}
	if *config != "" {
		_, err := toml.DecodeFile(*config, &cfg)
		if err != nil {
			log.Fatalf("ERROR: failed to load config file %s - %s", *config, err.Error())
		}
	}

	opts := nsqlookupd.NewNSQLookupdOptions()
	options.Resolve(opts, flagSet, cfg)
	p.daemon = nsqlookupd.NewNSQLookupd(opts)

	p.daemon.Main()

	return nil
}
Exemplo n.º 2
0
func main() {
	flagSet.Parse(os.Args[1:])

	if *showVersion {
		fmt.Println(util.Version("nsqlookupd"))
		return
	}

	signalChan := make(chan os.Signal, 1)
	exitChan := make(chan int)
	go func() {
		<-signalChan
		exitChan <- 1
	}()
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

	var cfg map[string]interface{}
	if *config != "" {
		_, err := toml.DecodeFile(*config, &cfg)
		if err != nil {
			log.Fatalf("ERROR: failed to load config file %s - %s", *config, err.Error())
		}
	}

	options := nsqlookupd.NewNSQLookupdOptions()
	util.ResolveOptions(options, flagSet, cfg)
	daemon := nsqlookupd.NewNSQLookupd(options)

	log.Println(util.Version("nsqlookupd"))

	daemon.Main()
	<-exitChan
	daemon.Exit()
}
Exemplo n.º 3
0
// Start configures an instance of NSQLookupd and
// runs it in a separate goroutine
func (self *LookupNode) Start(wg *sync.WaitGroup) (err error) {
	daemonOpts := nsqlookupd.NewNSQLookupdOptions()

	cfg.FillNSQLookupdOptions(daemonOpts)

	daemon := nsqlookupd.NewNSQLookupd(daemonOpts)

	wg.Add(1)

	go func() {
		daemon.Main()
		if self.options.Verbose {
			log.Print("NSQLookupd daemon started.")
		}
		<-self.exitChan
		daemon.Exit()
		if self.options.Verbose {
			log.Print("NSQLookupd daemon stopped.")
		}
		wg.Done()
	}()
	return
}