Skip to content

Commit

Permalink
Small changes to the doorman server.
Browse files Browse the repository at this point in the history
- Allow to force server id.
- Add redirect from / to /debug/status.
  • Loading branch information
ryszard committed Feb 9, 2016
1 parent 2010453 commit 108f3d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/simplecluster/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
etcd: etcd --data-dir /tmp/etcd.data$PORT
doorman: doorman -logtostderr -config=./config.prototext -port=$PORT -debug_port=$(expr $PORT + 50) -etcd_endpoints=http://localhost:2379 -master_election_lock=/doorman.master
doorman: $GOPATH/bin/doorman -logtostderr -config=./config.prototext -port=$PORT -debug_port=$(expr $PORT + 50) -etcd_endpoints=http://localhost:2379 -master_election_lock=/doorman.master -hostname=localhost

22 changes: 12 additions & 10 deletions go/cmd/doorman/doorman_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ var (
debugPort = flag.Int("debug_port", 8081, "port to bind for HTTP debug info")
serverRole = flag.String("server_role", "root", "Role of this server in the server tree")
parent = flag.String("parent", "", "Address of the parent server which this server connects to")

config = flag.String("config", "", "file to load the config from (text protobufs)")
hostname = flag.String("hostname", "", "Use this as the hostname (if empty, use whatever the kernel reports")
config = flag.String("config", "", "file to load the config from (text protobufs)")

rpcDialTimeout = flag.Duration("doorman_rpc_dial_timeout", 5*time.Second, "timeout to use for connecting to the doorman server")

Expand Down Expand Up @@ -119,16 +119,18 @@ No resources in the store.
`
)

// getServerID returns a unique server id, consisting of a host:pid id.
// getServerID returns a unique server id, consisting of a host:port id.
func getServerID(port int) string {

hostname, err := os.Hostname()
if *hostname != "" {
return fmt.Sprintf("%s:%d", *hostname, port)
}
hn, err := os.Hostname()

if err != nil {
hostname = "unknown.localhost"
hn = "unknown.localhost"
}

return fmt.Sprintf("%s:%d", hostname, port)
return fmt.Sprintf("%s:%d", hn, port)
}

func main() {
Expand Down Expand Up @@ -214,10 +216,10 @@ func main() {
}
}()

// FIXME(ryszard): Add some sort of statusz capabilities.
status.AddStatusPart("Doorman", statusz, func(context.Context) interface{} { return dm.Status() })
// // Adds this new Doorman server for /statusz and /resourcez.
// server.AddStatuszPart("Doorman", statusz, func(context.Context) interface{} { return dm.Status() })

// Redirect form / to /debug/status.
http.Handle("/", http.RedirectHandler("/debug/status", http.StatusMovedPermanently))
AddServer(dm)

go http.ListenAndServe(fmt.Sprintf(":%v", *debugPort), nil)
Expand Down

0 comments on commit 108f3d7

Please sign in to comment.