mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Merge pull request #148 from wallyqs/cluster-listen-arg
Add --cluster_listen flag to set cluster addr and port
This commit is contained in:
40
gnatsd.go
40
gnatsd.go
@@ -4,6 +4,9 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -53,6 +56,7 @@ func main() {
|
||||
flag.BoolVar(&showVersion, "v", false, "Print version information.")
|
||||
flag.IntVar(&opts.ProfPort, "profile", 0, "Profiling HTTP port")
|
||||
flag.StringVar(&opts.RoutesStr, "routes", "", "Routes to actively solicit a connection.")
|
||||
flag.StringVar(&opts.ClusterListenStr, "cluster_listen", "", "Cluster url from which members can solicit routes.")
|
||||
flag.BoolVar(&showTlsHelp, "help_tls", false, "TLS help.")
|
||||
|
||||
flag.BoolVar(&opts.TLS, "tls", false, "Enable TLS.")
|
||||
@@ -113,6 +117,12 @@ func main() {
|
||||
// Configure TLS based on any present flags
|
||||
configureTLS(&opts)
|
||||
|
||||
// Configure cluster opts if explicitly set via flags.
|
||||
err = configureClusterOpts(&opts)
|
||||
if err != nil {
|
||||
server.PrintAndDie(err.Error())
|
||||
}
|
||||
|
||||
// Create the server with appropriate options.
|
||||
s := server.New(&opts)
|
||||
|
||||
@@ -189,3 +199,33 @@ func configureTLS(opts *server.Options) {
|
||||
server.PrintAndDie(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func configureClusterOpts(opts *server.Options) error {
|
||||
if opts.ClusterListenStr == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
clusterUrl, err := url.Parse(opts.ClusterListenStr)
|
||||
h, p, err := net.SplitHostPort(clusterUrl.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.ClusterHost = h
|
||||
_, err = fmt.Sscan(p, &opts.ClusterPort)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if clusterUrl.User != nil {
|
||||
pass, hasPassword := clusterUrl.User.Password()
|
||||
if !hasPassword {
|
||||
return fmt.Errorf("Expected cluster password to be set.")
|
||||
}
|
||||
opts.ClusterPassword = pass
|
||||
|
||||
user := clusterUrl.User.Username()
|
||||
opts.ClusterUsername = user
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/gnatsd/conf"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Options block for gnatsd server.
|
||||
@@ -44,6 +44,7 @@ type Options struct {
|
||||
ClusterAuthTimeout float64 `json:"auth_timeout"`
|
||||
ClusterTLSTimeout float64 `json:"-"`
|
||||
ClusterTLSConfig *tls.Config `json:"-"`
|
||||
ClusterListenStr string `json:"-"`
|
||||
ProfPort int `json:"-"`
|
||||
PidFile string `json:"-"`
|
||||
LogFile string `json:"-"`
|
||||
|
||||
Reference in New Issue
Block a user