Moving port parameter to servenv.

This commit is contained in:
Alain Jobart 2014-03-06 10:31:49 -08:00
Родитель 500c34e604
Коммит de8060b3f1
8 изменённых файлов: 16 добавлений и 20 удалений

Просмотреть файл

@ -22,7 +22,6 @@ import (
) )
var ( var (
port = flag.Int("port", 0, "port for debug http server")
action = flag.String("action", "", "management action to perform") action = flag.String("action", "", "management action to perform")
actionNode = flag.String("action-node", "", "path to zk node representing the action") actionNode = flag.String("action-node", "", "path to zk node representing the action")
actionGuid = flag.String("action-guid", "", "a label to help track processes") 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 // we delegate out startup to the micromanagement server so these actions
// will occur after we have obtained our socket. // will occur after we have obtained our socket.
bindAddr := fmt.Sprintf(":%v", *port) bindAddr := fmt.Sprintf(":%v", *servenv.Port)
httpServer := &http.Server{Addr: bindAddr} httpServer := &http.Server{Addr: bindAddr}
go func() { go func() {
if err := httpServer.ListenAndServe(); err != nil { if err := httpServer.ListenAndServe(); err != nil {

Просмотреть файл

@ -21,7 +21,6 @@ import (
) )
var ( var (
port = flag.Int("port", 8080, "port for the server")
templateDir = flag.String("templates", "", "directory containing templates") templateDir = flag.String("templates", "", "directory containing templates")
debug = flag.Bool("debug", false, "recompile templates for every request") debug = flag.Bool("debug", false, "recompile templates for every request")
) )
@ -630,5 +629,5 @@ func main() {
} }
http.Redirect(w, r, target, http.StatusFound) http.Redirect(w, r, target, http.StatusFound)
}) })
servenv.Run(*port) servenv.Run()
} }

Просмотреть файл

@ -15,7 +15,6 @@ import (
) )
var ( var (
port = flag.Int("port", 8085, "serving port")
cell = flag.String("cell", "test_nj", "cell to use") cell = flag.String("cell", "test_nj", "cell to use")
retryDelay = flag.Duration("retry-delay", 200*time.Millisecond, "retry delay") retryDelay = flag.Duration("retry-delay", 200*time.Millisecond, "retry delay")
retryCount = flag.Int("retry-count", 10, "retry count") retryCount = flag.Int("retry-count", 10, "retry count")
@ -40,5 +39,5 @@ func main() {
topo.RegisterTopoReader(topoReader) topo.RegisterTopoReader(topoReader)
vtgate.Init(rts, *cell, *retryDelay, *retryCount, *timeout) vtgate.Init(rts, *cell, *retryDelay, *retryCount, *timeout)
servenv.Run(*port) servenv.Run()
} }

Просмотреть файл

@ -18,7 +18,6 @@ import (
) )
var ( var (
port = flag.Int("port", 6510, "tcp port to serve on")
overridesFile = flag.String("schema-override", "", "schema overrides file") overridesFile = flag.String("schema-override", "", "schema overrides file")
enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche") enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche")
enableInvalidator = flag.Bool("enable-invalidator", false, "enable rowcache invalidator") enableInvalidator = flag.Bool("enable-invalidator", false, "enable rowcache invalidator")
@ -53,12 +52,12 @@ func main() {
ts.AllowQueries(&dbConfigs.App, schemaOverrides, ts.LoadCustomRules(), mysqld) ts.AllowQueries(&dbConfigs.App, schemaOverrides, ts.LoadCustomRules(), mysqld)
log.Infof("starting vtocc %v", *port) log.Infof("starting vtocc %v", *servenv.Port)
servenv.OnClose(func() { servenv.OnClose(func() {
time.Sleep(5 * time.Millisecond) time.Sleep(5 * time.Millisecond)
ts.DisallowQueries() ts.DisallowQueries()
}) })
servenv.Run(*port) servenv.Run()
} }
func unmarshalFile(name string, val interface{}) { func unmarshalFile(name string, val interface{}) {

Просмотреть файл

@ -21,7 +21,6 @@ import (
) )
var ( 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") tabletPath = flag.String("tablet-path", "", "tablet alias or path to zk node representing the tablet")
mycnfFile = flag.String("mycnf-file", "", "my.cnf file") mycnfFile = flag.String("mycnf-file", "", "my.cnf file")
enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche") enableRowcache = flag.Bool("enable-rowcache", false, "enable rowcacche")
@ -57,7 +56,7 @@ func main() {
binlog.RegisterUpdateStreamService(mycnf) binlog.RegisterUpdateStreamService(mycnf)
// Depends on both query and updateStream. // 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -70,5 +69,5 @@ func main() {
topo.CloseServers() topo.CloseServers()
agent.Stop() agent.Stop()
}) })
servenv.Run(*port) servenv.Run()
} }

Просмотреть файл

@ -31,7 +31,6 @@ import (
var ( var (
cell = flag.String("cell", "", "cell to pick servers from") cell = flag.String("cell", "", "cell to pick servers from")
port = flag.Int("port", 8080, "port for the status / interactive mode")
) )
// signal handling, centralized here // signal handling, centralized here
@ -98,5 +97,5 @@ func main() {
} }
initStatusHandling() initStatusHandling()
servenv.Run(*port) servenv.Run()
} }

Просмотреть файл

@ -23,7 +23,6 @@ request to connect.
var ( var (
resolveLocal = flag.Bool("resolve-local", false, "if specified, will try to resolve /zk/local/ paths. If not set, they will fail.") 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() { func init() {
@ -43,5 +42,5 @@ func main() {
zk.RegisterZkReader(zkr) zk.RegisterZkReader(zkr)
topo.RegisterTopoReader(&TopoReader{zkr: zkr}) topo.RegisterTopoReader(&TopoReader{zkr: zkr})
servenv.Run(*port) servenv.Run()
} }

Просмотреть файл

@ -1,6 +1,7 @@
package servenv package servenv
import ( import (
"flag"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -14,18 +15,20 @@ import (
var ( var (
onCloseHooks hooks onCloseHooks hooks
Port = flag.Int("port", 0, "port for the server")
// filled in when calling Run or RunSecure // filled in when calling Run or RunSecure
ListeningURL url.URL 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. // and blocks until it the process gets a signal.
// It may also listen on a secure port, or on a unix socket. // It may also listen on a secure port, or on a unix socket.
func Run(port int) { func Run() {
onRunHooks.Fire() onRunHooks.Fire()
ServeRPC() ServeRPC()
l, err := proc.Listen(fmt.Sprintf("%v", port)) l, err := proc.Listen(fmt.Sprintf("%v", *Port))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -39,7 +42,7 @@ func Run(port int) {
} }
ListeningURL = url.URL{ ListeningURL = url.URL{
Scheme: "http", Scheme: "http",
Host: fmt.Sprintf("%v:%v", host, port), Host: fmt.Sprintf("%v:%v", host, *Port),
Path: "/", Path: "/",
} }