From de8060b3f1a1f74f8d3eff7b1f46ed46f33aaf19 Mon Sep 17 00:00:00 2001 From: Alain Jobart Date: Thu, 6 Mar 2014 10:31:49 -0800 Subject: [PATCH] Moving port parameter to servenv. --- go/cmd/vtaction/vtaction.go | 3 +-- go/cmd/vtctld/vtctld.go | 3 +-- go/cmd/vtgate/vtgate.go | 3 +-- go/cmd/vtocc/vtocc.go | 5 ++--- go/cmd/vttablet/vttablet.go | 5 ++--- go/cmd/vtworker/vtworker.go | 3 +-- go/cmd/zkocc/zkocc.go | 3 +-- go/vt/servenv/run.go | 11 +++++++---- 8 files changed, 16 insertions(+), 20 deletions(-) diff --git a/go/cmd/vtaction/vtaction.go b/go/cmd/vtaction/vtaction.go index 5569fa3ed7..318bd090f3 100644 --- a/go/cmd/vtaction/vtaction.go +++ b/go/cmd/vtaction/vtaction.go @@ -22,7 +22,6 @@ import ( ) var ( - port = flag.Int("port", 0, "port for debug http server") action = flag.String("action", "", "management action to perform") actionNode = flag.String("action-node", "", "path to zk node representing the action") actionGuid = flag.String("action-guid", "", "a label to help track processes") @@ -65,7 +64,7 @@ func main() { // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. - bindAddr := fmt.Sprintf(":%v", *port) + bindAddr := fmt.Sprintf(":%v", *servenv.Port) httpServer := &http.Server{Addr: bindAddr} go func() { if err := httpServer.ListenAndServe(); err != nil { diff --git a/go/cmd/vtctld/vtctld.go b/go/cmd/vtctld/vtctld.go index 9ed2ad4307..22d949d446 100644 --- a/go/cmd/vtctld/vtctld.go +++ b/go/cmd/vtctld/vtctld.go @@ -21,7 +21,6 @@ import ( ) var ( - port = flag.Int("port", 8080, "port for the server") templateDir = flag.String("templates", "", "directory containing templates") debug = flag.Bool("debug", false, "recompile templates for every request") ) @@ -630,5 +629,5 @@ func main() { } http.Redirect(w, r, target, http.StatusFound) }) - servenv.Run(*port) + servenv.Run() } diff --git a/go/cmd/vtgate/vtgate.go b/go/cmd/vtgate/vtgate.go index c9c8f36e19..9f29af9e37 100644 --- a/go/cmd/vtgate/vtgate.go +++ b/go/cmd/vtgate/vtgate.go @@ -15,7 +15,6 @@ import ( ) var ( - port = flag.Int("port", 8085, "serving port") cell = flag.String("cell", "test_nj", "cell to use") retryDelay = flag.Duration("retry-delay", 200*time.Millisecond, "retry delay") retryCount = flag.Int("retry-count", 10, "retry count") @@ -40,5 +39,5 @@ func main() { topo.RegisterTopoReader(topoReader) vtgate.Init(rts, *cell, *retryDelay, *retryCount, *timeout) - servenv.Run(*port) + servenv.Run() } diff --git a/go/cmd/vtocc/vtocc.go b/go/cmd/vtocc/vtocc.go index b630b85e74..37c0b1f5bd 100644 --- a/go/cmd/vtocc/vtocc.go +++ b/go/cmd/vtocc/vtocc.go @@ -18,7 +18,6 @@ import ( ) var ( - port = flag.Int("port", 6510, "tcp port to serve on") overridesFile = flag.String("schema-override", "", "schema overrides file") enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche") enableInvalidator = flag.Bool("enable-invalidator", false, "enable rowcache invalidator") @@ -53,12 +52,12 @@ func main() { ts.AllowQueries(&dbConfigs.App, schemaOverrides, ts.LoadCustomRules(), mysqld) - log.Infof("starting vtocc %v", *port) + log.Infof("starting vtocc %v", *servenv.Port) servenv.OnClose(func() { time.Sleep(5 * time.Millisecond) ts.DisallowQueries() }) - servenv.Run(*port) + servenv.Run() } func unmarshalFile(name string, val interface{}) { diff --git a/go/cmd/vttablet/vttablet.go b/go/cmd/vttablet/vttablet.go index 95a6b59a68..23315d144e 100644 --- a/go/cmd/vttablet/vttablet.go +++ b/go/cmd/vttablet/vttablet.go @@ -21,7 +21,6 @@ import ( ) var ( - port = flag.Int("port", 6509, "port for the server") tabletPath = flag.String("tablet-path", "", "tablet alias or path to zk node representing the tablet") mycnfFile = flag.String("mycnf-file", "", "my.cnf file") enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche") @@ -57,7 +56,7 @@ func main() { binlog.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. - agent, err = vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *port, *servenv.SecurePort, *overridesFile) + agent, err = vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *servenv.Port, *servenv.SecurePort, *overridesFile) if err != nil { log.Fatal(err) } @@ -70,5 +69,5 @@ func main() { topo.CloseServers() agent.Stop() }) - servenv.Run(*port) + servenv.Run() } diff --git a/go/cmd/vtworker/vtworker.go b/go/cmd/vtworker/vtworker.go index f19d356d03..2a3000ff69 100644 --- a/go/cmd/vtworker/vtworker.go +++ b/go/cmd/vtworker/vtworker.go @@ -31,7 +31,6 @@ import ( var ( cell = flag.String("cell", "", "cell to pick servers from") - port = flag.Int("port", 8080, "port for the status / interactive mode") ) // signal handling, centralized here @@ -98,5 +97,5 @@ func main() { } initStatusHandling() - servenv.Run(*port) + servenv.Run() } diff --git a/go/cmd/zkocc/zkocc.go b/go/cmd/zkocc/zkocc.go index f61ef27278..1a296cc1ab 100644 --- a/go/cmd/zkocc/zkocc.go +++ b/go/cmd/zkocc/zkocc.go @@ -23,7 +23,6 @@ request to connect. var ( resolveLocal = flag.Bool("resolve-local", false, "if specified, will try to resolve /zk/local/ paths. If not set, they will fail.") - port = flag.Int("port", 14850, "port for the server") ) func init() { @@ -43,5 +42,5 @@ func main() { zk.RegisterZkReader(zkr) topo.RegisterTopoReader(&TopoReader{zkr: zkr}) - servenv.Run(*port) + servenv.Run() } diff --git a/go/vt/servenv/run.go b/go/vt/servenv/run.go index 18456b6149..f46e9fd4bd 100644 --- a/go/vt/servenv/run.go +++ b/go/vt/servenv/run.go @@ -1,6 +1,7 @@ package servenv import ( + "flag" "fmt" "net/http" "net/url" @@ -14,18 +15,20 @@ import ( var ( onCloseHooks hooks + Port = flag.Int("port", 0, "port for the server") + // filled in when calling Run or RunSecure ListeningURL url.URL ) -// Run starts listening for RPC and HTTP requests on the given port, +// Run starts listening for RPC and HTTP requests, // and blocks until it the process gets a signal. // It may also listen on a secure port, or on a unix socket. -func Run(port int) { +func Run() { onRunHooks.Fire() ServeRPC() - l, err := proc.Listen(fmt.Sprintf("%v", port)) + l, err := proc.Listen(fmt.Sprintf("%v", *Port)) if err != nil { log.Fatal(err) } @@ -39,7 +42,7 @@ func Run(port int) { } ListeningURL = url.URL{ Scheme: "http", - Host: fmt.Sprintf("%v:%v", host, port), + Host: fmt.Sprintf("%v:%v", host, *Port), Path: "/", }