2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-07-13 02:21:18 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-07-13 02:21:18 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-12-18 11:26:30 -05:00
|
|
|
"net"
|
2021-08-05 18:01:19 -04:00
|
|
|
"net/url"
|
2016-07-13 02:21:18 -04:00
|
|
|
"strings"
|
|
|
|
|
2023-10-02 09:39:47 -04:00
|
|
|
"github.com/minio/minio/internal/color"
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/logger"
|
2024-05-24 19:05:23 -04:00
|
|
|
xnet "github.com/minio/pkg/v3/net"
|
2016-07-13 02:21:18 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2020-10-09 12:59:52 -04:00
|
|
|
func printStartupMessage(apiEndpoints []string, err error) {
|
2024-07-12 16:51:54 -04:00
|
|
|
banner := strings.Repeat("-", len(MinioBannerName))
|
|
|
|
if globalIsDistErasure {
|
|
|
|
logger.Startup(color.Bold(banner))
|
|
|
|
}
|
|
|
|
logger.Startup(color.Bold(MinioBannerName))
|
2020-10-09 12:59:52 -04:00
|
|
|
if err != nil {
|
2022-03-03 16:21:16 -05:00
|
|
|
if globalConsoleSys != nil {
|
2023-05-09 00:20:31 -04:00
|
|
|
globalConsoleSys.Send(GlobalContext, fmt.Sprintf("Server startup failed with '%v', some features may be missing", err))
|
2022-03-03 16:21:16 -05:00
|
|
|
}
|
2020-10-09 12:59:52 -04:00
|
|
|
}
|
2017-04-12 12:22:35 -04:00
|
|
|
|
2022-10-27 03:20:01 -04:00
|
|
|
if !globalSubnetConfig.Registered() {
|
2022-06-28 19:37:40 -04:00
|
|
|
var builder strings.Builder
|
|
|
|
startupBanner(&builder)
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(builder.String())
|
2022-06-27 06:58:25 -04:00
|
|
|
}
|
|
|
|
|
2021-06-21 02:04:47 -04:00
|
|
|
strippedAPIEndpoints := stripStandardPorts(apiEndpoints, globalMinioHost)
|
2019-11-09 12:27:23 -05:00
|
|
|
|
2017-01-10 19:43:48 -05:00
|
|
|
// Prints credential, region and browser access.
|
2017-05-31 12:21:28 -04:00
|
|
|
printServerCommonMsg(strippedAPIEndpoints)
|
2017-01-10 19:43:48 -05:00
|
|
|
|
|
|
|
// Prints `mc` cli configuration message chooses
|
|
|
|
// first endpoint as default.
|
2017-06-09 22:50:51 -04:00
|
|
|
printCLIAccessMsg(strippedAPIEndpoints[0], "myminio")
|
2017-01-10 19:43:48 -05:00
|
|
|
|
|
|
|
// Prints documentation message.
|
2016-07-13 02:21:18 -04:00
|
|
|
printObjectAPIMsg()
|
2024-07-12 16:51:54 -04:00
|
|
|
if globalIsDistErasure {
|
|
|
|
logger.Startup(color.Bold(banner))
|
|
|
|
}
|
2016-07-13 02:21:18 -04:00
|
|
|
}
|
|
|
|
|
2021-08-05 18:01:19 -04:00
|
|
|
// Returns true if input is IPv6
|
|
|
|
func isIPv6(host string) bool {
|
2018-12-18 11:26:30 -05:00
|
|
|
h, _, err := net.SplitHostPort(host)
|
|
|
|
if err != nil {
|
|
|
|
h = host
|
|
|
|
}
|
|
|
|
ip := net.ParseIP(h)
|
2021-08-05 18:01:19 -04:00
|
|
|
return ip.To16() != nil && ip.To4() == nil
|
2018-12-18 11:26:30 -05:00
|
|
|
}
|
|
|
|
|
2017-05-31 12:21:28 -04:00
|
|
|
// strip api endpoints list with standard ports such as
|
|
|
|
// port "80" and "443" before displaying on the startup
|
|
|
|
// banner. Returns a new list of API endpoints.
|
2021-06-21 02:04:47 -04:00
|
|
|
func stripStandardPorts(apiEndpoints []string, host string) (newAPIEndpoints []string) {
|
2021-08-05 18:01:19 -04:00
|
|
|
if len(apiEndpoints) == 1 {
|
|
|
|
return apiEndpoints
|
2021-07-23 18:22:25 -04:00
|
|
|
}
|
2017-05-31 12:21:28 -04:00
|
|
|
newAPIEndpoints = make([]string, len(apiEndpoints))
|
|
|
|
// Check all API endpoints for standard ports and strip them.
|
|
|
|
for i, apiEndpoint := range apiEndpoints {
|
2021-08-05 18:01:19 -04:00
|
|
|
_, err := xnet.ParseHTTPURL(apiEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
u, err := url.Parse(apiEndpoint)
|
2017-05-31 12:21:28 -04:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2021-08-05 18:01:19 -04:00
|
|
|
if host == "" && isIPv6(u.Hostname()) {
|
|
|
|
// Skip all IPv6 endpoints
|
2018-12-18 11:26:30 -05:00
|
|
|
continue
|
|
|
|
}
|
2021-08-05 18:01:19 -04:00
|
|
|
if u.Port() == "80" && u.Scheme == "http" || u.Port() == "443" && u.Scheme == "https" {
|
|
|
|
u.Host = u.Hostname()
|
|
|
|
}
|
2018-12-18 11:26:30 -05:00
|
|
|
newAPIEndpoints[i] = u.String()
|
2017-05-31 12:21:28 -04:00
|
|
|
}
|
|
|
|
return newAPIEndpoints
|
|
|
|
}
|
|
|
|
|
2016-07-13 02:21:18 -04:00
|
|
|
// Prints common server startup message. Prints credential, region and browser access.
|
2017-01-10 19:43:48 -05:00
|
|
|
func printServerCommonMsg(apiEndpoints []string) {
|
2016-07-13 02:21:18 -04:00
|
|
|
// Get saved credentials.
|
2019-10-23 01:59:13 -04:00
|
|
|
cred := globalActiveCred
|
2016-07-13 02:21:18 -04:00
|
|
|
|
|
|
|
// Get saved region.
|
2024-05-16 19:13:47 -04:00
|
|
|
region := globalSite.Region()
|
2016-07-13 02:21:18 -04:00
|
|
|
|
2024-03-08 22:07:08 -05:00
|
|
|
apiEndpointStr := strings.TrimSpace(strings.Join(apiEndpoints, " "))
|
2016-07-13 02:21:18 -04:00
|
|
|
// Colorize the message and print.
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(color.Blue("API: ") + color.Bold(fmt.Sprintf("%s ", apiEndpointStr)))
|
2024-03-01 16:09:42 -05:00
|
|
|
if color.IsTerminal() && (!globalServerCtxt.Anonymous && !globalServerCtxt.JSON && globalAPIConfig.permitRootAccess()) {
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(color.Blue(" RootUser: ") + color.Bold("%s ", cred.AccessKey))
|
|
|
|
logger.Startup(color.Blue(" RootPass: ") + color.Bold("%s \n", cred.SecretKey))
|
2018-10-16 16:19:12 -04:00
|
|
|
if region != "" {
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(color.Blue(" Region: ") + color.Bold("%s", fmt.Sprintf(getFormatStr(len(region), 2), region)))
|
2018-10-16 16:19:12 -04:00
|
|
|
}
|
2017-05-15 21:17:02 -04:00
|
|
|
}
|
2021-04-29 22:01:43 -04:00
|
|
|
|
|
|
|
if globalBrowserEnabled {
|
2021-06-21 02:04:47 -04:00
|
|
|
consoleEndpointStr := strings.Join(stripStandardPorts(getConsoleEndpoints(), globalMinioConsoleHost), " ")
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(color.Blue("WebUI: ") + color.Bold(fmt.Sprintf("%s ", consoleEndpointStr)))
|
2024-03-01 16:09:42 -05:00
|
|
|
if color.IsTerminal() && (!globalServerCtxt.Anonymous && !globalServerCtxt.JSON && globalAPIConfig.permitRootAccess()) {
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(color.Blue(" RootUser: ") + color.Bold("%s ", cred.AccessKey))
|
|
|
|
logger.Startup(color.Blue(" RootPass: ") + color.Bold("%s ", cred.SecretKey))
|
2021-06-17 23:27:04 -04:00
|
|
|
}
|
2021-04-29 22:01:43 -04:00
|
|
|
}
|
2023-04-15 10:34:02 -04:00
|
|
|
|
|
|
|
printEventNotifiers()
|
|
|
|
printLambdaTargets()
|
2016-09-13 14:00:40 -04:00
|
|
|
}
|
|
|
|
|
2022-09-29 00:28:45 -04:00
|
|
|
// Prints startup message for Object API access, prints link to our SDK documentation.
|
2021-06-17 23:27:04 -04:00
|
|
|
func printObjectAPIMsg() {
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(color.Blue("\nDocs: ") + "https://min.io/docs/minio/linux/index.html")
|
2021-06-17 23:27:04 -04:00
|
|
|
}
|
|
|
|
|
2023-03-07 11:12:41 -05:00
|
|
|
func printLambdaTargets() {
|
|
|
|
if globalLambdaTargetList == nil || globalLambdaTargetList.Empty() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
arnMsg := color.Blue("Object Lambda ARNs: ")
|
2024-05-16 19:13:47 -04:00
|
|
|
for _, arn := range globalLambdaTargetList.List(globalSite.Region()) {
|
2023-03-07 11:12:41 -05:00
|
|
|
arnMsg += color.Bold(fmt.Sprintf("%s ", arn))
|
|
|
|
}
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(arnMsg + "\n")
|
2023-03-07 11:12:41 -05:00
|
|
|
}
|
|
|
|
|
2016-09-13 14:00:40 -04:00
|
|
|
// Prints bucket notification configurations.
|
|
|
|
func printEventNotifiers() {
|
2019-11-13 20:38:05 -05:00
|
|
|
if globalNotificationSys == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-20 10:46:02 -04:00
|
|
|
arns := globalEventNotifier.GetARNList()
|
2018-03-15 16:03:41 -04:00
|
|
|
if len(arns) == 0 {
|
2017-05-15 21:17:02 -04:00
|
|
|
return
|
2016-09-13 14:00:40 -04:00
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
|
2019-10-04 13:35:33 -04:00
|
|
|
arnMsg := color.Blue("SQS ARNs: ")
|
2018-03-15 16:03:41 -04:00
|
|
|
for _, arn := range arns {
|
2021-01-06 13:38:07 -05:00
|
|
|
arnMsg += color.Bold(fmt.Sprintf("%s ", arn))
|
2016-09-10 05:23:28 -04:00
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(arnMsg + "\n")
|
2016-07-13 02:21:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prints startup message for command line access. Prints link to our documentation
|
|
|
|
// and custom platform specific message.
|
2017-06-09 22:50:51 -04:00
|
|
|
func printCLIAccessMsg(endPoint string, alias string) {
|
2016-07-13 02:21:18 -04:00
|
|
|
// Get saved credentials.
|
2019-10-23 01:59:13 -04:00
|
|
|
cred := globalActiveCred
|
2016-07-13 02:21:18 -04:00
|
|
|
|
2022-09-29 00:28:45 -04:00
|
|
|
const mcQuickStartGuide = "https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart"
|
2021-06-17 23:27:04 -04:00
|
|
|
|
2016-07-13 02:21:18 -04:00
|
|
|
// Configure 'mc', following block prints platform specific information for minio client.
|
2024-03-01 16:09:42 -05:00
|
|
|
if color.IsTerminal() && (!globalServerCtxt.Anonymous && globalAPIConfig.permitRootAccess()) {
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(color.Blue("\nCLI: ") + mcQuickStartGuide)
|
2023-10-02 09:39:47 -04:00
|
|
|
mcMessage := fmt.Sprintf("$ mc alias set '%s' '%s' '%s' '%s'", alias,
|
|
|
|
endPoint, cred.AccessKey, cred.SecretKey)
|
2024-07-12 16:51:54 -04:00
|
|
|
logger.Startup(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage))
|
2018-05-23 20:30:25 -04:00
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|