| 
									
										
										
										
											2021-04-19 03:41:13 +08: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/>.
 | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2020-04-17 02:54:12 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2020-04-17 02:54:12 +08:00
										 |  |  | 	"net" | 
					
						
							| 
									
										
										
										
											2017-04-12 08:44:26 +08:00
										 |  |  | 	"net/url" | 
					
						
							| 
									
										
										
										
											2017-07-13 07:33:21 +08:00
										 |  |  | 	"os" | 
					
						
							|  |  |  | 	"os/signal" | 
					
						
							| 
									
										
										
										
											2017-04-12 08:44:26 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2017-07-13 07:33:21 +08:00
										 |  |  | 	"syscall" | 
					
						
							| 
									
										
										
										
											2017-06-06 06:18:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/gorilla/mux" | 
					
						
							|  |  |  | 	"github.com/minio/cli" | 
					
						
							| 
									
										
										
										
											2021-06-15 03:53:49 +08:00
										 |  |  | 	"github.com/minio/madmin-go" | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 	xhttp "github.com/minio/minio/internal/http" | 
					
						
							|  |  |  | 	"github.com/minio/minio/internal/logger" | 
					
						
							| 
									
										
										
										
											2021-05-29 06:17:01 +08:00
										 |  |  | 	"github.com/minio/pkg/certs" | 
					
						
							|  |  |  | 	"github.com/minio/pkg/env" | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | var ( | 
					
						
							|  |  |  | 	gatewayCmd = cli.Command{ | 
					
						
							|  |  |  | 		Name:            "gateway", | 
					
						
							| 
									
										
										
										
											2018-11-21 09:35:33 +08:00
										 |  |  | 		Usage:           "start object storage gateway", | 
					
						
							| 
									
										
										
										
											2019-06-10 22:57:42 +08:00
										 |  |  | 		Flags:           append(ServerFlags, GlobalFlags...), | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | 		HideHelpCommand: true, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2017-06-09 14:28:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 08:07:23 +08:00
										 |  |  | // GatewayLocker implements custom NewNSLock implementation
 | 
					
						
							|  |  |  | type GatewayLocker struct { | 
					
						
							|  |  |  | 	ObjectLayer | 
					
						
							|  |  |  | 	nsMutex *nsLockMap | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewNSLock - implements gateway level locker
 | 
					
						
							| 
									
										
										
										
											2020-11-05 00:25:42 +08:00
										 |  |  | func (l *GatewayLocker) NewNSLock(bucket string, objects ...string) RWLocker { | 
					
						
							|  |  |  | 	return l.nsMutex.NewNSLock(nil, bucket, objects...) | 
					
						
							| 
									
										
										
										
											2020-06-30 08:07:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Walk - implements common gateway level Walker, to walk on all objects recursively at a prefix
 | 
					
						
							| 
									
										
										
										
											2020-07-11 13:21:04 +08:00
										 |  |  | func (l *GatewayLocker) Walk(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo, opts ObjectOptions) error { | 
					
						
							| 
									
										
										
										
											2020-06-30 08:07:23 +08:00
										 |  |  | 	walk := func(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo) error { | 
					
						
							| 
									
										
										
										
											2020-07-27 13:56:05 +08:00
										 |  |  | 		go func() { | 
					
						
							|  |  |  | 			// Make sure the results channel is ready to be read when we're done.
 | 
					
						
							|  |  |  | 			defer close(results) | 
					
						
							| 
									
										
										
										
											2020-07-02 05:29:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-27 13:56:05 +08:00
										 |  |  | 			var marker string | 
					
						
							| 
									
										
										
										
											2020-07-02 05:29:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-27 13:56:05 +08:00
										 |  |  | 			for { | 
					
						
							|  |  |  | 				// set maxKeys to '0' to list maximum possible objects in single call.
 | 
					
						
							|  |  |  | 				loi, err := l.ObjectLayer.ListObjects(ctx, bucket, prefix, marker, "", 0) | 
					
						
							|  |  |  | 				if err != nil { | 
					
						
							|  |  |  | 					logger.LogIf(ctx, err) | 
					
						
							|  |  |  | 					return | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				marker = loi.NextMarker | 
					
						
							|  |  |  | 				for _, obj := range loi.Objects { | 
					
						
							|  |  |  | 					select { | 
					
						
							|  |  |  | 					case results <- obj: | 
					
						
							|  |  |  | 					case <-ctx.Done(): | 
					
						
							|  |  |  | 						return | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if !loi.IsTruncated { | 
					
						
							|  |  |  | 					break | 
					
						
							| 
									
										
										
										
											2020-06-30 08:07:23 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-07-27 13:56:05 +08:00
										 |  |  | 		}() | 
					
						
							| 
									
										
										
										
											2020-06-30 08:07:23 +08:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-11 13:21:04 +08:00
										 |  |  | 	if err := l.ObjectLayer.Walk(ctx, bucket, prefix, results, opts); err != nil { | 
					
						
							| 
									
										
										
										
											2020-06-30 08:07:23 +08:00
										 |  |  | 		if _, ok := err.(NotImplemented); ok { | 
					
						
							|  |  |  | 			return walk(ctx, bucket, prefix, results) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewGatewayLayerWithLocker - initialize gateway with locker.
 | 
					
						
							|  |  |  | func NewGatewayLayerWithLocker(gwLayer ObjectLayer) ObjectLayer { | 
					
						
							|  |  |  | 	return &GatewayLocker{ObjectLayer: gwLayer, nsMutex: newNSLock(false)} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-28 06:07:46 +08:00
										 |  |  | // RegisterGatewayCommand registers a new command for gateway.
 | 
					
						
							|  |  |  | func RegisterGatewayCommand(cmd cli.Command) error { | 
					
						
							| 
									
										
										
										
											2019-07-04 05:31:19 +08:00
										 |  |  | 	cmd.Flags = append(append(cmd.Flags, ServerFlags...), GlobalFlags...) | 
					
						
							| 
									
										
										
										
											2017-10-28 06:07:46 +08:00
										 |  |  | 	gatewayCmd.Subcommands = append(gatewayCmd.Subcommands, cmd) | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 09:58:09 +08:00
										 |  |  | // ParseGatewayEndpoint - Return endpoint.
 | 
					
						
							|  |  |  | func ParseGatewayEndpoint(arg string) (endPoint string, secure bool, err error) { | 
					
						
							| 
									
										
										
										
											2017-04-12 08:44:26 +08:00
										 |  |  | 	schemeSpecified := len(strings.Split(arg, "://")) > 1 | 
					
						
							|  |  |  | 	if !schemeSpecified { | 
					
						
							|  |  |  | 		// Default connection will be "secure".
 | 
					
						
							|  |  |  | 		arg = "https://" + arg | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-28 02:26:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-12 08:44:26 +08:00
										 |  |  | 	u, err := url.Parse(arg) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return "", false, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch u.Scheme { | 
					
						
							|  |  |  | 	case "http": | 
					
						
							|  |  |  | 		return u.Host, false, nil | 
					
						
							|  |  |  | 	case "https": | 
					
						
							|  |  |  | 		return u.Host, true, nil | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return "", false, fmt.Errorf("Unrecognized scheme %s", u.Scheme) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 09:58:09 +08:00
										 |  |  | // ValidateGatewayArguments - Validate gateway arguments.
 | 
					
						
							|  |  |  | func ValidateGatewayArguments(serverAddr, endpointAddr string) error { | 
					
						
							| 
									
										
										
										
											2017-06-09 02:20:56 +08:00
										 |  |  | 	if err := CheckLocalServerAddr(serverAddr); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if endpointAddr != "" { | 
					
						
							|  |  |  | 		// Reject the endpoint if it points to the gateway handler itself.
 | 
					
						
							|  |  |  | 		sameTarget, err := sameLocalAddrs(endpointAddr, serverAddr) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if sameTarget { | 
					
						
							| 
									
										
										
										
											2017-11-26 03:58:29 +08:00
										 |  |  | 			return fmt.Errorf("endpoint points to the local gateway") | 
					
						
							| 
									
										
										
										
											2017-06-09 02:20:56 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 09:58:09 +08:00
										 |  |  | // StartGateway - handler for 'minio gateway <name>'.
 | 
					
						
							|  |  |  | func StartGateway(ctx *cli.Context, gw Gateway) { | 
					
						
							| 
									
										
										
										
											2020-10-17 05:49:05 +08:00
										 |  |  | 	defer globalDNSCache.Stop() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-18 11:27:04 +08:00
										 |  |  | 	signal.Notify(globalOSSignalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	go handleSignals() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	signal.Notify(globalOSSignalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) | 
					
						
							| 
									
										
										
										
											2020-05-19 02:35:05 +08:00
										 |  |  | 	// This is only to uniquely identify each gateway deployments.
 | 
					
						
							|  |  |  | 	globalDeploymentID = env.Get("MINIO_GATEWAY_DEPLOYMENT_ID", mustGetUUID()) | 
					
						
							|  |  |  | 	logger.SetDeploymentID(globalDeploymentID) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 09:58:09 +08:00
										 |  |  | 	if gw == nil { | 
					
						
							| 
									
										
										
										
											2018-05-10 06:11:24 +08:00
										 |  |  | 		logger.FatalIf(errUnexpected, "Gateway implementation not initialized") | 
					
						
							| 
									
										
										
										
											2017-12-06 09:58:09 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Validate if we have access, secret set through environment.
 | 
					
						
							| 
									
										
										
										
											2019-08-15 02:43:43 +08:00
										 |  |  | 	globalGatewayName = gw.Name() | 
					
						
							| 
									
										
										
										
											2017-12-06 09:58:09 +08:00
										 |  |  | 	gatewayName := gw.Name() | 
					
						
							|  |  |  | 	if ctx.Args().First() == "help" { | 
					
						
							|  |  |  | 		cli.ShowCommandHelpAndExit(ctx, gatewayName, 1) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-16 09:02:54 +08:00
										 |  |  | 	// Initialize globalConsoleSys system
 | 
					
						
							|  |  |  | 	globalConsoleSys = NewConsoleLogger(GlobalContext) | 
					
						
							|  |  |  | 	logger.AddTarget(globalConsoleSys) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | 	// Handle common command args.
 | 
					
						
							|  |  |  | 	handleCommonCmdArgs(ctx) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 09:03:16 +08:00
										 |  |  | 	// Check and load TLS certificates.
 | 
					
						
							|  |  |  | 	var err error | 
					
						
							| 
									
										
										
										
											2020-12-22 13:42:38 +08:00
										 |  |  | 	globalPublicCerts, globalTLSCerts, globalIsTLS, err = getTLSConfig() | 
					
						
							| 
									
										
										
										
											2020-08-07 09:03:16 +08:00
										 |  |  | 	logger.FatalIf(err, "Invalid TLS certificate file") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check and load Root CAs.
 | 
					
						
							| 
									
										
										
										
											2020-08-11 23:29:50 +08:00
										 |  |  | 	globalRootCAs, err = certs.GetRootCAs(globalCertsCADir.Get()) | 
					
						
							| 
									
										
										
										
											2020-08-07 09:03:16 +08:00
										 |  |  | 	logger.FatalIf(err, "Failed to read root CAs (%v)", err) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 00:46:50 +08:00
										 |  |  | 	// Add the global public crts as part of global root CAs
 | 
					
						
							|  |  |  | 	for _, publicCrt := range globalPublicCerts { | 
					
						
							|  |  |  | 		globalRootCAs.AddCert(publicCrt) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 09:03:16 +08:00
										 |  |  | 	// Register root CAs for remote ENVs
 | 
					
						
							|  |  |  | 	env.RegisterGlobalCAs(globalRootCAs) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-05 07:32:37 +08:00
										 |  |  | 	// Initialize all help
 | 
					
						
							|  |  |  | 	initHelp() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-18 12:06:36 +08:00
										 |  |  | 	// On macOS, if a process already listens on LOCALIPADDR:PORT, net.Listen() falls back
 | 
					
						
							|  |  |  | 	// to IPv6 address ie minio will start listening on IPv6 address whereas another
 | 
					
						
							|  |  |  | 	// (non-)minio process is listening on IPv4 of given port.
 | 
					
						
							|  |  |  | 	// To avoid this error situation we check for port availability.
 | 
					
						
							| 
									
										
										
										
											2019-06-25 06:02:40 +08:00
										 |  |  | 	logger.FatalIf(checkPortAvailability(globalMinioHost, globalMinioPort), "Unable to start the gateway") | 
					
						
							| 
									
										
										
										
											2018-08-18 12:06:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 	// Handle gateway specific env
 | 
					
						
							| 
									
										
										
										
											2019-11-02 06:53:16 +08:00
										 |  |  | 	gatewayHandleEnvVars() | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-24 22:39:30 +08:00
										 |  |  | 	// Set system resources to maximum.
 | 
					
						
							| 
									
										
										
										
											2020-06-17 09:57:29 +08:00
										 |  |  | 	setMaxResources() | 
					
						
							| 
									
										
										
										
											2017-12-24 22:39:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-08 06:49:13 +08:00
										 |  |  | 	// Set when gateway is enabled
 | 
					
						
							|  |  |  | 	globalIsGateway = true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 19:16:25 +08:00
										 |  |  | 	// TODO: We need to move this code with globalConfigSys.Init()
 | 
					
						
							|  |  |  | 	// for now keep it here such that "s3" gateway layer initializes
 | 
					
						
							|  |  |  | 	// itself properly when KMS is set.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Initialize server config.
 | 
					
						
							|  |  |  | 	srvCfg := newServerConfig() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Override any values from ENVs.
 | 
					
						
							| 
									
										
										
										
											2021-01-23 04:09:24 +08:00
										 |  |  | 	lookupConfigs(srvCfg, nil) | 
					
						
							| 
									
										
										
										
											2019-11-12 19:16:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// hold the mutex lock before a new config is assigned.
 | 
					
						
							|  |  |  | 	globalServerConfigMu.Lock() | 
					
						
							|  |  |  | 	globalServerConfig = srvCfg | 
					
						
							|  |  |  | 	globalServerConfigMu.Unlock() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-12 11:38:02 +08:00
										 |  |  | 	// Initialize router. `SkipClean(true)` stops gorilla/mux from
 | 
					
						
							|  |  |  | 	// normalizing URL path minio/minio#3256
 | 
					
						
							|  |  |  | 	// avoid URL path encoding minio/minio#8950
 | 
					
						
							|  |  |  | 	router := mux.NewRouter().SkipClean(true).UseEncodedPath() | 
					
						
							| 
									
										
										
										
											2017-06-02 00:43:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-10 23:32:52 +08:00
										 |  |  | 	// Enable STS router if etcd is enabled.
 | 
					
						
							|  |  |  | 	registerSTSRouter(router) | 
					
						
							| 
									
										
										
										
											2019-01-24 03:10:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 05:03:26 +08:00
										 |  |  | 	// Enable IAM admin APIs if etcd is enabled, if not just enable basic
 | 
					
						
							|  |  |  | 	// operations such as profiling, server info etc.
 | 
					
						
							| 
									
										
										
										
											2021-09-02 02:34:07 +08:00
										 |  |  | 	registerAdminRouter(router, false) | 
					
						
							| 
									
										
										
										
											2018-12-19 05:03:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-05 10:07:54 +08:00
										 |  |  | 	// Add healthcheck router
 | 
					
						
							|  |  |  | 	registerHealthCheckRouter(router) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-30 12:43:46 +08:00
										 |  |  | 	// Add server metrics router
 | 
					
						
							|  |  |  | 	registerMetricsRouter(router) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-05 10:07:54 +08:00
										 |  |  | 	// Add API router.
 | 
					
						
							| 
									
										
										
										
											2020-09-16 04:57:15 +08:00
										 |  |  | 	registerAPIRouter(router) | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-11 23:19:55 +08:00
										 |  |  | 	// Use all the middlewares
 | 
					
						
							| 
									
										
										
										
											2021-01-05 01:54:22 +08:00
										 |  |  | 	router.Use(globalHandlers...) | 
					
						
							| 
									
										
										
										
											2020-06-11 23:19:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 03:30:15 +08:00
										 |  |  | 	var getCert certs.GetCertificateFunc | 
					
						
							|  |  |  | 	if globalTLSCerts != nil { | 
					
						
							|  |  |  | 		getCert = globalTLSCerts.GetCertificate | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-21 14:04:47 +08:00
										 |  |  | 	httpServer := xhttp.NewServer([]string{globalMinioAddr}, | 
					
						
							| 
									
										
										
										
											2020-07-13 01:56:57 +08:00
										 |  |  | 		criticalErrorHandler{corsHandler(router)}, getCert) | 
					
						
							| 
									
										
										
										
											2020-04-17 02:54:12 +08:00
										 |  |  | 	httpServer.BaseContext = func(listener net.Listener) context.Context { | 
					
						
							|  |  |  | 		return GlobalContext | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | 	go func() { | 
					
						
							| 
									
										
										
										
											2019-12-03 07:54:26 +08:00
										 |  |  | 		globalHTTPServerErrorCh <- httpServer.Start() | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | 	}() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 07:54:26 +08:00
										 |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	globalHTTPServer = httpServer | 
					
						
							|  |  |  | 	globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-15 03:53:49 +08:00
										 |  |  | 	newObject, err := gw.NewGatewayLayer(madmin.Credentials{ | 
					
						
							|  |  |  | 		AccessKey: globalActiveCred.AccessKey, | 
					
						
							|  |  |  | 		SecretKey: globalActiveCred.SecretKey, | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2018-12-19 02:42:09 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		logger.FatalIf(err, "Unable to initialize gateway backend") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-20 08:45:35 +08:00
										 |  |  | 	newObject = NewGatewayLayerWithLocker(newObject) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 00:54:40 +08:00
										 |  |  | 	// Calls all New() for all sub-systems.
 | 
					
						
							|  |  |  | 	newAllSubsystems() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	// Once endpoints are finalized, initialize the new object api in safe mode.
 | 
					
						
							|  |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	globalObjectAPI = newObject | 
					
						
							|  |  |  | 	globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 23:52:46 +08:00
										 |  |  | 	if gatewayName == NASBackendGateway { | 
					
						
							| 
									
										
										
										
											2020-04-10 00:30:02 +08:00
										 |  |  | 		buckets, err := newObject.ListBuckets(GlobalContext) | 
					
						
							| 
									
										
										
										
											2020-02-02 17:52:07 +08:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			logger.Fatal(err, "Unable to list buckets") | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-08-21 01:38:53 +08:00
										 |  |  | 		logger.FatalIf(globalNotificationSys.Init(GlobalContext, buckets, newObject), "Unable to initialize notification system") | 
					
						
							| 
									
										
										
										
											2018-12-19 02:42:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-13 03:25:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-10 23:32:52 +08:00
										 |  |  | 	go globalIAMSys.Init(GlobalContext, newObject) | 
					
						
							| 
									
										
										
										
											2018-10-10 05:00:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	if globalCacheConfig.Enabled { | 
					
						
							|  |  |  | 		// initialize the new disk cache objects.
 | 
					
						
							|  |  |  | 		var cacheAPI CacheObjectLayer | 
					
						
							| 
									
										
										
										
											2020-03-23 03:16:36 +08:00
										 |  |  | 		cacheAPI, err = newServerCacheObjects(GlobalContext, globalCacheConfig) | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 		logger.FatalIf(err, "Unable to initialize disk caching") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 		globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 		globalCacheObjectAPI = cacheAPI | 
					
						
							|  |  |  | 		globalObjLayerMutex.Unlock() | 
					
						
							| 
									
										
										
										
											2019-10-31 14:39:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-12-15 05:35:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-18 05:50:07 +08:00
										 |  |  | 	// Populate existing buckets to the etcd backend
 | 
					
						
							|  |  |  | 	if globalDNSConfig != nil { | 
					
						
							| 
									
										
										
										
											2020-03-23 03:16:36 +08:00
										 |  |  | 		buckets, err := newObject.ListBuckets(GlobalContext) | 
					
						
							| 
									
										
										
										
											2019-12-18 05:50:07 +08:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			logger.Fatal(err, "Unable to list buckets") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		initFederatorBackend(buckets, newObject) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-26 17:41:16 +08:00
										 |  |  | 	// Verify if object layer supports
 | 
					
						
							|  |  |  | 	// - encryption
 | 
					
						
							|  |  |  | 	// - compression
 | 
					
						
							|  |  |  | 	verifyObjectLayerFeatures("gateway "+gatewayName, newObject) | 
					
						
							| 
									
										
										
										
											2018-12-15 05:35:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | 	// Prints the formatted startup message once object layer is initialized.
 | 
					
						
							| 
									
										
										
										
											2021-06-15 03:53:49 +08:00
										 |  |  | 	if !globalCLIContext.Quiet && !globalInplaceUpdateDisabled { | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | 		// Check update mode.
 | 
					
						
							| 
									
										
										
										
											2021-06-15 03:53:49 +08:00
										 |  |  | 		checkUpdate(globalMinioModeGatewayPrefix + gatewayName) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-06 09:58:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-15 03:53:49 +08:00
										 |  |  | 	if !globalCLIContext.Quiet { | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | 		// Print gateway startup message.
 | 
					
						
							| 
									
										
										
										
											2018-12-14 15:37:46 +08:00
										 |  |  | 		printGatewayStartupMessage(getAPIEndpoints(), gatewayName) | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-18 11:27:04 +08:00
										 |  |  | 	if globalBrowserEnabled { | 
					
						
							| 
									
										
										
										
											2021-09-01 09:52:48 +08:00
										 |  |  | 		globalConsoleSrv, err = initConsoleServer() | 
					
						
							| 
									
										
										
										
											2021-06-18 11:27:04 +08:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			logger.FatalIf(err, "Unable to initialize console service") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		go func() { | 
					
						
							| 
									
										
										
										
											2021-09-01 09:52:48 +08:00
										 |  |  | 			logger.FatalIf(globalConsoleSrv.Serve(), "Unable to initialize console server") | 
					
						
							| 
									
										
										
										
											2021-06-18 11:27:04 +08:00
										 |  |  | 		}() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-09-01 09:52:48 +08:00
										 |  |  | 	<-globalOSSignalCh | 
					
						
							| 
									
										
										
										
											2017-03-17 03:21:58 +08:00
										 |  |  | } |