2017-06-09 22:50:51 -04:00
|
|
|
|
/*
|
2018-02-28 23:13:33 -05:00
|
|
|
|
* Minio Cloud Storage, (C) 2017, 2018 Minio, Inc.
|
2017-06-09 22:50:51 -04:00
|
|
|
|
*
|
|
|
|
|
* 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 cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
2018-03-29 17:38:26 -04:00
|
|
|
|
"strconv"
|
2017-06-09 22:50:51 -04:00
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/minio/cli"
|
2017-10-31 14:54:32 -04:00
|
|
|
|
"github.com/minio/minio/pkg/auth"
|
2017-06-09 22:50:51 -04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Check for updates and print a notification message
|
|
|
|
|
func checkUpdate(mode string) {
|
2017-12-15 15:33:42 -05:00
|
|
|
|
// Its OK to ignore any errors during doUpdate() here.
|
|
|
|
|
if updateMsg, _, currentReleaseTime, latestReleaseTime, err := getUpdateInfo(2*time.Second, mode); err == nil {
|
|
|
|
|
if globalInplaceUpdateDisabled {
|
2017-06-09 22:50:51 -04:00
|
|
|
|
log.Println(updateMsg)
|
2017-12-15 15:33:42 -05:00
|
|
|
|
} else {
|
|
|
|
|
log.Println(prepareUpdateMessage("Run `minio update`", latestReleaseTime.Sub(currentReleaseTime)))
|
2017-06-09 22:50:51 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initConfig() {
|
|
|
|
|
// Config file does not exist, we create it fresh and return upon success.
|
|
|
|
|
if isFile(getConfigFile()) {
|
|
|
|
|
fatalIf(migrateConfig(), "Config migration failed.")
|
2017-11-29 16:12:47 -05:00
|
|
|
|
fatalIf(loadConfig(), "Unable to load config version: '%s'.", serverConfigVersion)
|
2017-06-09 22:50:51 -04:00
|
|
|
|
} else {
|
|
|
|
|
fatalIf(newConfig(), "Unable to initialize minio config for the first time.")
|
|
|
|
|
log.Println("Created minio configuration file successfully at " + getConfigDir())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleCommonCmdArgs(ctx *cli.Context) {
|
2018-02-28 23:13:33 -05:00
|
|
|
|
|
|
|
|
|
var configDir string
|
|
|
|
|
|
|
|
|
|
if ctx.IsSet("config-dir") {
|
|
|
|
|
configDir = ctx.String("config-dir")
|
|
|
|
|
} else if ctx.GlobalIsSet("config-dir") {
|
|
|
|
|
configDir = ctx.GlobalString("config-dir")
|
|
|
|
|
// cli package does not expose parent's "config-dir" option. Below code is workaround.
|
|
|
|
|
if configDir == "" || configDir == getConfigDir() {
|
|
|
|
|
if ctx.Parent().GlobalIsSet("config-dir") {
|
|
|
|
|
configDir = ctx.Parent().GlobalString("config-dir")
|
|
|
|
|
}
|
2017-06-09 22:50:51 -04:00
|
|
|
|
}
|
2018-02-28 23:13:33 -05:00
|
|
|
|
} else {
|
|
|
|
|
// Neither local nor global config-dir option is provided. In this case, try to use
|
|
|
|
|
// default config directory.
|
|
|
|
|
configDir = getConfigDir()
|
2017-06-09 22:50:51 -04:00
|
|
|
|
if configDir == "" {
|
2018-02-28 23:13:33 -05:00
|
|
|
|
fatalIf(errors.New("missing option"), "config-dir option must be provided.")
|
2017-06-09 22:50:51 -04:00
|
|
|
|
}
|
2018-02-28 23:13:33 -05:00
|
|
|
|
}
|
2017-06-09 22:50:51 -04:00
|
|
|
|
|
2018-02-28 23:13:33 -05:00
|
|
|
|
if configDir == "" {
|
|
|
|
|
fatalIf(errors.New("empty directory"), "Configuration directory cannot be empty.")
|
2017-06-09 22:50:51 -04:00
|
|
|
|
}
|
2018-02-28 23:13:33 -05:00
|
|
|
|
|
|
|
|
|
// Disallow relative paths, figure out absolute paths.
|
|
|
|
|
configDirAbs, err := filepath.Abs(configDir)
|
|
|
|
|
fatalIf(err, "Unable to fetch absolute path for config directory %s", configDir)
|
|
|
|
|
setConfigDir(configDirAbs)
|
2017-06-09 22:50:51 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleCommonEnvVars() {
|
|
|
|
|
// Start profiler if env is set.
|
|
|
|
|
if profiler := os.Getenv("_MINIO_PROFILER"); profiler != "" {
|
|
|
|
|
globalProfiler = startProfiler(profiler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
|
|
|
|
secretKey := os.Getenv("MINIO_SECRET_KEY")
|
|
|
|
|
if accessKey != "" && secretKey != "" {
|
2017-10-31 14:54:32 -04:00
|
|
|
|
cred, err := auth.CreateCredentials(accessKey, secretKey)
|
2017-06-09 22:50:51 -04:00
|
|
|
|
fatalIf(err, "Invalid access/secret Key set in environment.")
|
|
|
|
|
|
|
|
|
|
// credential Envs are set globally.
|
|
|
|
|
globalIsEnvCreds = true
|
|
|
|
|
globalActiveCred = cred
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if browser := os.Getenv("MINIO_BROWSER"); browser != "" {
|
|
|
|
|
browserFlag, err := ParseBrowserFlag(browser)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fatalIf(errors.New("invalid value"), "Unknown value ‘%s’ in MINIO_BROWSER environment variable.", browser)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// browser Envs are set globally, this does not represent
|
|
|
|
|
// if browser is turned off or on.
|
|
|
|
|
globalIsEnvBrowser = true
|
|
|
|
|
globalIsBrowserEnabled = bool(browserFlag)
|
|
|
|
|
}
|
2017-10-24 22:04:51 -04:00
|
|
|
|
|
2018-01-05 14:24:31 -05:00
|
|
|
|
traceFile := os.Getenv("MINIO_HTTP_TRACE")
|
|
|
|
|
if traceFile != "" {
|
|
|
|
|
var err error
|
|
|
|
|
globalHTTPTraceFile, err = os.OpenFile(traceFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660)
|
|
|
|
|
fatalIf(err, "error opening file %s", traceFile)
|
|
|
|
|
}
|
2017-11-14 19:56:24 -05:00
|
|
|
|
|
|
|
|
|
globalDomainName = os.Getenv("MINIO_DOMAIN")
|
|
|
|
|
if globalDomainName != "" {
|
|
|
|
|
globalIsEnvDomainName = true
|
|
|
|
|
}
|
2017-12-15 15:33:42 -05:00
|
|
|
|
|
2018-03-28 17:14:06 -04:00
|
|
|
|
if drives := os.Getenv("MINIO_CACHE_DRIVES"); drives != "" {
|
2018-03-29 17:38:26 -04:00
|
|
|
|
driveList, err := parseCacheDrives(strings.Split(drives, cacheEnvDelimiter))
|
|
|
|
|
fatalIf(err, "Invalid value set in environment variable MINIO_CACHE_DRIVES %s.", drives)
|
2018-03-28 17:14:06 -04:00
|
|
|
|
globalCacheDrives = driveList
|
|
|
|
|
globalIsDiskCacheEnabled = true
|
|
|
|
|
}
|
|
|
|
|
if excludes := os.Getenv("MINIO_CACHE_EXCLUDE"); excludes != "" {
|
2018-03-29 17:38:26 -04:00
|
|
|
|
excludeList, err := parseCacheExcludes(strings.Split(excludes, cacheEnvDelimiter))
|
|
|
|
|
fatalIf(err, "Invalid value set in environment variable MINIO_CACHE_EXCLUDE %s.", excludes)
|
2018-03-28 17:14:06 -04:00
|
|
|
|
globalCacheExcludes = excludeList
|
|
|
|
|
}
|
|
|
|
|
if expiryStr := os.Getenv("MINIO_CACHE_EXPIRY"); expiryStr != "" {
|
2018-03-29 17:38:26 -04:00
|
|
|
|
expiry, err := strconv.Atoi(expiryStr)
|
|
|
|
|
fatalIf(err, "Invalid value set in environment variable MINIO_CACHE_EXPIRY %s.", expiryStr)
|
2018-03-28 17:14:06 -04:00
|
|
|
|
globalCacheExpiry = expiry
|
|
|
|
|
}
|
2018-03-29 17:38:26 -04:00
|
|
|
|
|
2017-12-15 15:33:42 -05:00
|
|
|
|
// In place update is true by default if the MINIO_UPDATE is not set
|
|
|
|
|
// or is not set to 'off', if MINIO_UPDATE is set to 'off' then
|
|
|
|
|
// in-place update is off.
|
|
|
|
|
globalInplaceUpdateDisabled = strings.EqualFold(os.Getenv("MINIO_UPDATE"), "off")
|
2017-12-22 06:28:13 -05:00
|
|
|
|
|
|
|
|
|
// Validate and store the storage class env variables only for XL/Dist XL setups
|
|
|
|
|
if globalIsXL {
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
// Check for environment variables and parse into storageClass struct
|
2017-12-26 23:36:16 -05:00
|
|
|
|
if ssc := os.Getenv(standardStorageClassEnv); ssc != "" {
|
2017-12-22 06:28:13 -05:00
|
|
|
|
globalStandardStorageClass, err = parseStorageClass(ssc)
|
2017-12-26 23:36:16 -05:00
|
|
|
|
fatalIf(err, "Invalid value set in environment variable %s.", standardStorageClassEnv)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 23:36:16 -05:00
|
|
|
|
if rrsc := os.Getenv(reducedRedundancyStorageClassEnv); rrsc != "" {
|
2017-12-22 06:28:13 -05:00
|
|
|
|
globalRRStorageClass, err = parseStorageClass(rrsc)
|
2017-12-26 23:36:16 -05:00
|
|
|
|
fatalIf(err, "Invalid value set in environment variable %s.", reducedRedundancyStorageClassEnv)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validation is done after parsing both the storage classes. This is needed because we need one
|
|
|
|
|
// storage class value to deduce the correct value of the other storage class.
|
|
|
|
|
if globalRRStorageClass.Scheme != "" {
|
2018-02-01 02:30:07 -05:00
|
|
|
|
err = validateParity(globalStandardStorageClass.Parity, globalRRStorageClass.Parity)
|
2017-12-26 23:36:16 -05:00
|
|
|
|
fatalIf(err, "Invalid value set in environment variable %s.", reducedRedundancyStorageClassEnv)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
globalIsStorageClass = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if globalStandardStorageClass.Scheme != "" {
|
2018-02-01 02:30:07 -05:00
|
|
|
|
err = validateParity(globalStandardStorageClass.Parity, globalRRStorageClass.Parity)
|
2017-12-26 23:36:16 -05:00
|
|
|
|
fatalIf(err, "Invalid value set in environment variable %s.", standardStorageClassEnv)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
globalIsStorageClass = true
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-27 19:44:45 -04:00
|
|
|
|
|
|
|
|
|
// Get WORM environment variable.
|
|
|
|
|
globalWORMEnabled = strings.EqualFold(os.Getenv("MINIO_WORM"), "on")
|
2017-06-09 22:50:51 -04:00
|
|
|
|
}
|