server: Change server startup message. (#2195)
This change brings in the new agreed startup message for the server. Adds additional links point to Minio SDKs as well.master
parent
0610527868
commit
3b69b4ada4
@ -0,0 +1,93 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"errors" |
||||
"net" |
||||
"os" |
||||
"syscall" |
||||
) |
||||
|
||||
// Make sure that none of the other processes are listening on the
|
||||
// specified port on any of the interfaces.
|
||||
//
|
||||
// On linux if a process is listening on 127.0.0.1:9000 then Listen()
|
||||
// on ":9000" fails with the error "port already in use".
|
||||
// However on Mac OSX Listen() on ":9000" falls back to the IPv6 address.
|
||||
// This causes confusion on Mac OSX that minio server is not reachable
|
||||
// on 127.0.0.1 even though minio server is running. So before we start
|
||||
// the minio server we make sure that the port is free on all the IPs.
|
||||
func checkPortAvailability(port int) { |
||||
isAddrInUse := func(err error) bool { |
||||
// Check if the syscall error is EADDRINUSE.
|
||||
// EADDRINUSE is the system call error if another process is
|
||||
// already listening at the specified port.
|
||||
neterr, ok := err.(*net.OpError) |
||||
if !ok { |
||||
return false |
||||
} |
||||
osErr, ok := neterr.Err.(*os.SyscallError) |
||||
if !ok { |
||||
return false |
||||
} |
||||
sysErr, ok := osErr.Err.(syscall.Errno) |
||||
if !ok { |
||||
return false |
||||
} |
||||
if sysErr != syscall.EADDRINUSE { |
||||
return false |
||||
} |
||||
return true |
||||
} |
||||
ifcs, err := net.Interfaces() |
||||
if err != nil { |
||||
fatalIf(err, "Unable to list interfaces.") |
||||
} |
||||
for _, ifc := range ifcs { |
||||
addrs, err := ifc.Addrs() |
||||
if err != nil { |
||||
fatalIf(err, "Unable to list addresses on interface %s.", ifc.Name) |
||||
} |
||||
for _, addr := range addrs { |
||||
ipnet, ok := addr.(*net.IPNet) |
||||
if !ok { |
||||
errorIf(errors.New(""), "Failed to assert type on (*net.IPNet) interface.") |
||||
continue |
||||
} |
||||
ip := ipnet.IP |
||||
network := "tcp4" |
||||
if ip.To4() == nil { |
||||
network = "tcp6" |
||||
} |
||||
tcpAddr := net.TCPAddr{IP: ip, Port: port, Zone: ifc.Name} |
||||
l, err := net.ListenTCP(network, &tcpAddr) |
||||
if err != nil { |
||||
if isAddrInUse(err) { |
||||
// Fail if port is already in use.
|
||||
fatalIf(err, "Unable to listen on %s:%.d.", tcpAddr.IP, tcpAddr.Port) |
||||
} else { |
||||
// Ignore other errors.
|
||||
continue |
||||
} |
||||
} |
||||
if err = l.Close(); err != nil { |
||||
fatalIf(err, "Unable to close listener on %s:%.d.", tcpAddr.IP, tcpAddr.Port) |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,92 @@ |
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"runtime" |
||||
"strings" |
||||
|
||||
"github.com/minio/mc/pkg/console" |
||||
) |
||||
|
||||
// Documentation links, these are part of message printing code.
|
||||
const ( |
||||
mcQuickStartGuide = "https://docs.minio.io/docs/minio-client-quick-start-guide" |
||||
goQuickStartGuide = "https://docs.minio.io/docs/golang-client-quickstart-guide" |
||||
jsQuickStartGuide = "https://docs.minio.io/docs/javascript-client-quickstart-guide" |
||||
javaQuickStartGuide = "https://docs.minio.io/docs/java-client-quickstart-guide" |
||||
pyQuickStartGuide = "https://docs.minio.io/docs/python-client-quickstart-guide" |
||||
) |
||||
|
||||
// generates format string depending on the string length and padding.
|
||||
func getFormatStr(strLen int, padding int) string { |
||||
formatStr := fmt.Sprintf("%ds", strLen+padding) |
||||
return "%" + formatStr |
||||
} |
||||
|
||||
// Prints the formatted startup message.
|
||||
func printStartupMessage(endPoints []string) { |
||||
printServerCommonMsg(endPoints) |
||||
printCLIAccessMsg(endPoints[0]) |
||||
printObjectAPIMsg() |
||||
} |
||||
|
||||
// Prints common server startup message. Prints credential, region and browser access.
|
||||
func printServerCommonMsg(endPoints []string) { |
||||
// Get saved credentials.
|
||||
cred := serverConfig.GetCredential() |
||||
|
||||
// Get saved region.
|
||||
region := serverConfig.GetRegion() |
||||
|
||||
endPointStr := strings.Join(endPoints, " ") |
||||
// Colorize the message and print.
|
||||
console.Println(colorMagenta("\nEndpoint: ") + colorGreen(fmt.Sprintf(getFormatStr(len(endPointStr), 1), endPointStr))) |
||||
console.Println(colorMagenta("AccessKey: ") + colorWhite(fmt.Sprintf("%s ", cred.AccessKeyID))) |
||||
console.Println(colorMagenta("SecretKey: ") + colorWhite(fmt.Sprintf("%s ", cred.SecretAccessKey))) |
||||
console.Println(colorMagenta("Region: ") + colorWhite(fmt.Sprintf(getFormatStr(len(region), 3), region))) |
||||
|
||||
console.Println(colorMagenta("\nBrowser Access:")) |
||||
console.Println(colorGreen(fmt.Sprintf(getFormatStr(len(endPointStr), 3), endPointStr))) |
||||
} |
||||
|
||||
// Prints startup message for command line access. Prints link to our documentation
|
||||
// and custom platform specific message.
|
||||
func printCLIAccessMsg(endPoint string) { |
||||
// Get saved credentials.
|
||||
cred := serverConfig.GetCredential() |
||||
|
||||
// Configure 'mc', following block prints platform specific information for minio client.
|
||||
console.Println(colorMagenta("\nCommand-line Access: ") + colorWhite(mcQuickStartGuide)) |
||||
if runtime.GOOS == "windows" { |
||||
mcMessage := fmt.Sprintf("$ mc.exe config host add myminio %s %s %s", endPoint, cred.AccessKeyID, cred.SecretAccessKey) |
||||
console.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) |
||||
} else { |
||||
mcMessage := fmt.Sprintf("$ ./mc config host add myminio %s %s %s", endPoint, cred.AccessKeyID, cred.SecretAccessKey) |
||||
console.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) |
||||
} |
||||
} |
||||
|
||||
// Prints startup message for Object API acces, prints link to our SDK documentation.
|
||||
func printObjectAPIMsg() { |
||||
console.Println("\nObject API (Amazon S3 compatible):") |
||||
console.Println(" Go: " + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide)) |
||||
console.Println(" Java: " + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide)) |
||||
console.Println(" Python: " + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide)) |
||||
console.Println(" JavaScript: " + jsQuickStartGuide) |
||||
} |
Loading…
Reference in new issue