-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1140 from mdh67899/fix-nsqd-tcp-accept-error
nsqd/nsqlookupd: properly handle fatal accept errors
- Loading branch information
Showing
38 changed files
with
613 additions
and
595 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/BurntSushi/toml" | ||
"github.com/judwhite/go-svc/svc" | ||
"github.com/mreiferson/go-options" | ||
"github.com/nsqio/nsq/internal/lg" | ||
"github.com/nsqio/nsq/internal/version" | ||
"github.com/nsqio/nsq/nsqd" | ||
) | ||
|
||
type program struct { | ||
once sync.Once | ||
nsqd *nsqd.NSQD | ||
} | ||
|
||
func main() { | ||
prg := &program{} | ||
if err := svc.Run(prg, syscall.SIGINT, syscall.SIGTERM); err != nil { | ||
logFatal("%s", err) | ||
} | ||
} | ||
|
||
func (p *program) Init(env svc.Environment) error { | ||
if env.IsWindowsService() { | ||
dir := filepath.Dir(os.Args[0]) | ||
return os.Chdir(dir) | ||
} | ||
return nil | ||
} | ||
|
||
func (p *program) Start() error { | ||
opts := nsqd.NewOptions() | ||
|
||
flagSet := nsqdFlagSet(opts) | ||
flagSet.Parse(os.Args[1:]) | ||
|
||
rand.Seed(time.Now().UTC().UnixNano()) | ||
|
||
if flagSet.Lookup("version").Value.(flag.Getter).Get().(bool) { | ||
fmt.Println(version.String("nsqd")) | ||
os.Exit(0) | ||
} | ||
|
||
var cfg config | ||
configFile := flagSet.Lookup("config").Value.String() | ||
if configFile != "" { | ||
_, err := toml.DecodeFile(configFile, &cfg) | ||
if err != nil { | ||
logFatal("failed to load config file %s - %s", configFile, err) | ||
} | ||
} | ||
cfg.Validate() | ||
|
||
options.Resolve(opts, flagSet, cfg) | ||
nsqd, err := nsqd.New(opts) | ||
if err != nil { | ||
logFatal("failed to instantiate nsqd - %s", err) | ||
} | ||
p.nsqd = nsqd | ||
|
||
err = p.nsqd.LoadMetadata() | ||
if err != nil { | ||
logFatal("failed to load metadata - %s", err) | ||
} | ||
err = p.nsqd.PersistMetadata() | ||
if err != nil { | ||
logFatal("failed to persist metadata - %s", err) | ||
} | ||
|
||
go func() { | ||
err := p.nsqd.Main() | ||
if err != nil { | ||
p.Stop() | ||
os.Exit(1) | ||
} | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
func (p *program) Stop() error { | ||
p.once.Do(func() { | ||
p.nsqd.Exit() | ||
}) | ||
return nil | ||
} | ||
|
||
func logFatal(f string, args ...interface{}) { | ||
lg.LogFatal("[nsqd] ", f, args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.