diff --git a/cmd/common-main.go b/cmd/common-main.go index 079b98649..88ed51f8c 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -111,7 +111,7 @@ const consolePrefix = "CONSOLE_" func minioConfigToConsoleFeatures() { os.Setenv("CONSOLE_PBKDF_SALT", globalDeploymentID) os.Setenv("CONSOLE_PBKDF_PASSPHRASE", globalDeploymentID) - os.Setenv("CONSOLE_MINIO_SERVER", getAPIEndpoints()[0]) + os.Setenv("CONSOLE_MINIO_SERVER", globalMinioEndpoint) if value := env.Get("MINIO_LOG_QUERY_URL", ""); value != "" { os.Setenv("CONSOLE_LOG_QUERY_URL", value) if value := env.Get("MINIO_LOG_QUERY_AUTH_TOKEN", ""); value != "" { diff --git a/cmd/endpoint-v2.go b/cmd/endpoint-v2.go index 6af816f95..591a0705b 100644 --- a/cmd/endpoint-v2.go +++ b/cmd/endpoint-v2.go @@ -1,3 +1,20 @@ +// 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 . + package cmd import ( @@ -13,16 +30,20 @@ var ( ) const ( - driveSeparator = "=" + driveSeparator = "drives=" ) func parseDrives(cctx *cli.Context) (string, error) { + if !strings.Contains(cctx.Args().First(), driveSeparator) { + return "", nil + } tokens := strings.SplitN(cctx.Args().First(), driveSeparator, 2) if len(tokens) != 2 { return "", fmt.Errorf("unable to parse input args %s", cctx.Args()) } - if !ellipses.HasEllipses(tokens[1]) { + drives := strings.TrimSpace(tokens[1]) + if !ellipses.HasEllipses(drives) { return "", fmt.Errorf("unable to parse input args %s, only allows ellipses patterns", cctx.Args()) } - return tokens[1], nil + return drives, nil } diff --git a/cmd/server-main.go b/cmd/server-main.go index 0de6868e1..8550e6d99 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -444,8 +444,16 @@ func serverMain(ctx *cli.Context) { erasureSelfTest() compressSelfTest() - // Handle all server command args. - serverHandleCmdArgs(ctx) + drives, err := parseDrives(ctx) + if err != nil { + logger.Fatal(config.ErrUnexpectedError(err), "Unable to parse the input arguments") + } + if drives == "" { + // Handle all server command args. + serverHandleCmdArgs(ctx) + } else { + globalMinioDrives = drives + } // Handle all server environment vars. serverHandleEnvVars() diff --git a/cmd/volume-meta.go b/cmd/volume-meta.go new file mode 100644 index 000000000..e41e195e6 --- /dev/null +++ b/cmd/volume-meta.go @@ -0,0 +1,65 @@ +package cmd + +import ( + "encoding/json" + "io/ioutil" + "os" + "path/filepath" + "strings" + + "github.com/minio/pkg/ellipses" +) + +func expandDriveVolumeMeta(driveArg string) (drives []string, err error) { + patterns, err := ellipses.FindEllipsesPatterns(driveArg) + if err != nil { + return nil, err + } + for _, lbls := range patterns.Expand() { + driveAbs, err := filepath.Abs(strings.Join(lbls, "")) + if err != nil { + // fail for non-absolute paths + return nil, err + } + drives = append(drives, driveAbs) + } + return drives, nil +} + +type volumePool struct { + ID string `json:"id"` + Local string `json:"local"` + Remote string `json:"remote"` + CmdLine string `json:"cmdline"` +} + +type volumeMeta struct { + Version string `json:"version"` + Token string `json:"token"` + Pools []volumePool `json:"pools"` +} + +const volumeMetaFile = "volume.meta" + +func checkDriveVolumeMeta(driveArg string) (*volumeMeta, error) { + drives, err := expandDriveVolumeMeta(driveArg) + if err != nil { + return nil, err + } + volumeMetas := make([]*volumeMeta, len(drives)) + for i, drv := range drives { + buf, err := ioutil.ReadFile(filepath.Join(drv, minioMetaBucket, volumeMetaFile)) + if err != nil && !os.IsNotExist(err) { + return nil, err + } + if os.IsNotExist(err) { + continue + } + var vm = new(volumeMeta) + if err = json.Unmarshal(buf, vm); err != nil { + return nil, err + } + volumeMetas[i] = vm + } + return volumeMetas[0], nil +}