From da9ae574dfe1bf7782c43dc6bd5100f20b39f077 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 14 Sep 2016 01:11:03 -0700 Subject: [PATCH] server: We should fail properly during server startup. (#2689) Fixes #2688 --- cmd/server-main.go | 31 +++++++++++++++++-------------- cmd/server-startup-msg.go | 7 ++++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cmd/server-main.go b/cmd/server-main.go index 4ff9088dc..807a844db 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -388,28 +388,30 @@ func serverMain(c *cli.Context) { return exitSuccess }) - // Prints the formatted startup message. - printStartupMessage(endPoints) - // Start server. // Configure TLS if certs are available. wait := make(chan struct{}, 1) go func(tls bool, wait chan<- struct{}) { - if tls { - err = apiServer.ListenAndServeTLS(mustGetCertFile(), mustGetKeyFile()) - } else { - // Fallback to http. - err = apiServer.ListenAndServe() - } - wait <- struct{}{} - + fatalIf(func() error { + defer func() { + wait <- struct{}{} + }() + if tls { + return apiServer.ListenAndServeTLS(mustGetCertFile(), mustGetKeyFile()) + } // Fallback to http. + return apiServer.ListenAndServe() + }(), "Failed to start minio server.") }(tls, wait) + + // Wait for formatting of disks. err = formatDisks(disks, ignoredDisks) if err != nil { // FIXME: call graceful exit errorIf(err, "formatting storage disks failed") return } + + // Once formatted, initialize object layer. newObject, err := newObjectLayer(disks, ignoredDisks) if err != nil { // FIXME: call graceful exit @@ -417,12 +419,13 @@ func serverMain(c *cli.Context) { return } - printEventNotifiers() + // Prints the formatted startup message. + printStartupMessage(endPoints) objLayerMutex.Lock() globalObjectAPI = newObject objLayerMutex.Unlock() - <-wait - fatalIf(err, "Failed to start minio server.") + // Waits on the server. + <-wait } diff --git a/cmd/server-startup-msg.go b/cmd/server-startup-msg.go index b01d94b49..a91f80fc9 100644 --- a/cmd/server-startup-msg.go +++ b/cmd/server-startup-msg.go @@ -60,6 +60,7 @@ func printServerCommonMsg(endPoints []string) { console.Println(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKeyID))) console.Println(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretAccessKey))) console.Println(colorBlue("Region: ") + colorBold(fmt.Sprintf(getFormatStr(len(region), 3), region))) + printEventNotifiers() console.Println(colorBlue("\nBrowser Access:")) console.Println(fmt.Sprintf(getFormatStr(len(endPointStr), 3), endPointStr)) @@ -71,12 +72,12 @@ func printEventNotifiers() { // In case initEventNotifier() was not done or failed. return } - arnMsg := colorBlue("\nSQS ARNs: ") + arnMsg := colorBlue("SQS ARNs: ") if len(globalEventNotifier.queueTargets) == 0 { - arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(""), 2), "")) + arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(""), 1), "")) } for queueArn := range globalEventNotifier.queueTargets { - arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(queueArn), 2), queueArn)) + arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(queueArn), 1), queueArn)) } console.Println(arnMsg) }