-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nsqd/nsqlookupd: properly handle fatal accept errors #1140
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d66571c
nsqd: properly exit on fatal accept errors
mdh67899 61060a4
apps/nsqd: re-organize
mreiferson 6c840f8
nsqd: typed log-level
mreiferson 00b28f0
nsqd: move listener from Main to New
mreiferson 8e6768b
nsqlookupd: properly exit on fatal errors
mreiferson 05668cf
apps/nsqlookupd: re-organize
mreiferson 179052e
nsqlookupd: typed log-level
mreiferson 9c6da6c
nsqlookupd: move listener from Main to New
mreiferson 30a3c75
nsqadmin: switch to go-svc; update logging
mreiferson c888ddd
go.mod/Gopkg: update go-options
mreiferson ad5ed66
internal/lg: make LogLevel a flag.Value; refactor
mreiferson cf5526e
nsq_to_file: ParseLogLevel signature update
mreiferson 9d332eb
*: test updates
mreiferson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mreiferson It doesn't hurt anything to have this, but the package does this bit for you now. I generally consider it impolite to
os.Chdir
but in this case I thought it was warranted. https://github.com/judwhite/go-svc/blame/d83e900e4a688aad49f41263bebf8793f0bf6add/svc/svc_windows.go#L59-L66