mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-12 15:51:01 +00:00
support the various ways of specifying bind addr
This commit is contained in:
parent
74b79dd928
commit
5f267c0a3a
5 changed files with 26 additions and 10 deletions
|
|
@ -54,7 +54,7 @@ Build Time: ` + BuildTime + "\n",
|
|||
},
|
||||
}
|
||||
rc.PersistentFlags().Bool("dry-run", false, "stop before executing")
|
||||
rc.PersistentFlags().MarkHidden("dry-run")
|
||||
_ = rc.PersistentFlags().MarkHidden("dry-run")
|
||||
rc.PersistentFlags().StringP("config", "c", "", "Configuration file to read from.")
|
||||
for _, subcomFn := range subcommandFns {
|
||||
rc.AddCommand(subcomFn(stdin, stdout, stderr))
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ on the configured port.`,
|
|||
|
||||
// Execute the program.
|
||||
if err := Server.Run(); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("error running server: %v", err)
|
||||
}
|
||||
|
||||
// First SIGKILL causes server to shut down gracefully.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import "time"
|
|||
|
||||
const (
|
||||
// DefaultHost is the default hostname and port to use.
|
||||
DefaultHost = "localhost:15000"
|
||||
DefaultHost = "localhost"
|
||||
DefaultPort = "10101"
|
||||
)
|
||||
|
||||
// Config represents the configuration for the command.
|
||||
|
|
@ -30,7 +31,7 @@ type Config struct {
|
|||
// NewConfig returns an instance of Config with default options.
|
||||
func NewConfig() *Config {
|
||||
c := &Config{
|
||||
Host: DefaultHost,
|
||||
Host: DefaultHost + ":" + DefaultPort,
|
||||
}
|
||||
c.Cluster.ReplicaN = DefaultReplicaN
|
||||
c.Cluster.PollingInterval = Duration(DefaultPollingInterval)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package pilosa
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
|
@ -74,7 +73,7 @@ func (s *Server) Open() error {
|
|||
if err != nil {
|
||||
return err
|
||||
} else if port == "" {
|
||||
return errors.New("port must be specified in config host")
|
||||
port = DefaultPort
|
||||
}
|
||||
|
||||
// Open HTTP listener to determine port (if specified as :0).
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func NewCommand() *Command {
|
|||
}
|
||||
|
||||
// Run executes the pilosa server.
|
||||
func (m *Command) Run(args ...string) error {
|
||||
func (m *Command) Run(args ...string) (err error) {
|
||||
defer close(m.Started)
|
||||
prefix := "~" + string(filepath.Separator)
|
||||
if strings.HasPrefix(m.Config.DataDir, prefix) {
|
||||
|
|
@ -80,20 +80,36 @@ func (m *Command) Run(args ...string) error {
|
|||
m.Server.Index.Stats = pilosa.NewExpvarStatsClient()
|
||||
|
||||
// Build cluster from config file.
|
||||
m.Server.Host = m.Config.Host
|
||||
m.Server.Host, err = normalizeHost(m.Config.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Server.Cluster = m.Config.PilosaCluster()
|
||||
|
||||
// Set configuration options.
|
||||
m.Server.AntiEntropyInterval = time.Duration(m.Config.AntiEntropy.Interval)
|
||||
|
||||
// Initialize server.
|
||||
if err := m.Server.Open(); err != nil {
|
||||
return err
|
||||
if err = m.Server.Open(); err != nil {
|
||||
return fmt.Errorf("server.Open: %v", err)
|
||||
}
|
||||
fmt.Fprintf(m.Stderr, "Listening as http://%s\n", m.Server.Host)
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeHost(host string) (string, error) {
|
||||
if !strings.Contains(host, ":") {
|
||||
host = host + ":"
|
||||
} else if strings.Contains(host, "://") {
|
||||
if strings.HasPrefix(host, "http://") {
|
||||
host = host[7:]
|
||||
} else {
|
||||
return "", fmt.Errorf("invalid scheme or host: '%s'. use the format [http://]<host>:<port>", host)
|
||||
}
|
||||
}
|
||||
return host, nil
|
||||
}
|
||||
|
||||
// Close shuts down the server.
|
||||
func (m *Command) Close() error {
|
||||
err := m.Server.Close()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue