mirror of
https://github.com/minio/minio.git
synced 2025-04-20 10:37:31 -04:00
init: Honor config-dir flag when it is passed as global or local flag (#3337)
setGlobalsFromContext() is added to sets global variable after parsing command line arguments.
This commit is contained in:
parent
d711ff454e
commit
e2ef95af7d
@ -53,11 +53,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
globalQuiet = false // Quiet flag set via command line.
|
globalQuiet = false // quiet flag set via command line.
|
||||||
globalIsDistXL = false // "Is Distributed?" flag.
|
globalConfigDir = mustGetConfigPath() // config-dir flag set via command line
|
||||||
|
|
||||||
// Add new global flags here.
|
// Add new global flags here.
|
||||||
|
|
||||||
|
globalIsDistXL = false // "Is Distributed?" flag.
|
||||||
|
|
||||||
// Maximum cache size.
|
// Maximum cache size.
|
||||||
globalMaxCacheSize = uint64(maxCacheSize)
|
globalMaxCacheSize = uint64(maxCacheSize)
|
||||||
// Cache expiry.
|
// Cache expiry.
|
||||||
|
66
cmd/main.go
66
cmd/main.go
@ -148,19 +148,42 @@ func checkMainSyntax(c *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main main for minio server.
|
// Parse command arguments and set global variables accordingly
|
||||||
func Main() {
|
func setGlobalsFromContext(c *cli.Context) {
|
||||||
app := registerApp()
|
// Set config dir
|
||||||
app.Before = func(c *cli.Context) error {
|
switch {
|
||||||
configDir := c.GlobalString("config-dir")
|
case c.IsSet("config-dir"):
|
||||||
if configDir == "" {
|
globalConfigDir = c.String("config-dir")
|
||||||
|
case c.GlobalIsSet("config-dir"):
|
||||||
|
globalConfigDir = c.GlobalString("config-dir")
|
||||||
|
}
|
||||||
|
if globalConfigDir == "" {
|
||||||
fatalIf(errors.New("Config directory is empty"), "Unable to get config file.")
|
fatalIf(errors.New("Config directory is empty"), "Unable to get config file.")
|
||||||
}
|
}
|
||||||
// Sets new config directory.
|
// Set global quiet flag.
|
||||||
setGlobalConfigPath(configDir)
|
globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
|
||||||
|
}
|
||||||
|
|
||||||
// Valid input arguments to main.
|
// Check for updates and print a notification message
|
||||||
checkMainSyntax(c)
|
func checkUpdate() {
|
||||||
|
// Do not print update messages, if quiet flag is set.
|
||||||
|
if !globalQuiet {
|
||||||
|
updateMsg, _, err := getReleaseUpdate(minioUpdateStableURL, 1*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
// Ignore any errors during getReleaseUpdate(), possibly
|
||||||
|
// because of network errors.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if updateMsg.Update {
|
||||||
|
console.Println(updateMsg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic Minio initialization to create/load config, prepare loggers, etc..
|
||||||
|
func minioInit() {
|
||||||
|
// Sets new config directory.
|
||||||
|
setGlobalConfigPath(globalConfigDir)
|
||||||
|
|
||||||
// Migrate any old version of config / state files to newer format.
|
// Migrate any old version of config / state files to newer format.
|
||||||
migrate()
|
migrate()
|
||||||
@ -194,24 +217,15 @@ func Main() {
|
|||||||
|
|
||||||
// Init the error tracing module.
|
// Init the error tracing module.
|
||||||
initError()
|
initError()
|
||||||
|
}
|
||||||
|
|
||||||
// Set global quiet flag.
|
// Main main for minio server.
|
||||||
globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
|
func Main() {
|
||||||
|
app := registerApp()
|
||||||
|
app.Before = func(c *cli.Context) error {
|
||||||
|
// Valid input arguments to main.
|
||||||
|
checkMainSyntax(c)
|
||||||
|
|
||||||
// Do not print update messages, if quiet flag is set.
|
|
||||||
if !globalQuiet {
|
|
||||||
if c.Args().Get(0) != "update" {
|
|
||||||
updateMsg, _, err := getReleaseUpdate(minioUpdateStableURL, 1*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
// Ignore any errors during getReleaseUpdate(), possibly
|
|
||||||
// because of network errors.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if updateMsg.Update {
|
|
||||||
console.Println(updateMsg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,8 +363,13 @@ func serverMain(c *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(c, "server", 1)
|
cli.ShowCommandHelpAndExit(c, "server", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set global quiet flag.
|
// Set global variables after parsing passed arguments
|
||||||
globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
|
setGlobalsFromContext(c)
|
||||||
|
|
||||||
|
checkUpdate()
|
||||||
|
|
||||||
|
// Generic initialization
|
||||||
|
minioInit()
|
||||||
|
|
||||||
// Server address.
|
// Server address.
|
||||||
serverAddr := c.String("address")
|
serverAddr := c.String("address")
|
||||||
|
@ -265,8 +265,9 @@ func getReleaseUpdate(updateURL string, duration time.Duration) (updateMsg updat
|
|||||||
|
|
||||||
// main entry point for update command.
|
// main entry point for update command.
|
||||||
func mainUpdate(ctx *cli.Context) {
|
func mainUpdate(ctx *cli.Context) {
|
||||||
// Set global quiet flag.
|
|
||||||
if ctx.Bool("quiet") || ctx.GlobalBool("quiet") {
|
setGlobalsFromContext(ctx)
|
||||||
|
if globalQuiet {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,10 @@ func mainVersion(ctx *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(ctx, "version", 1)
|
cli.ShowCommandHelpAndExit(ctx, "version", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGlobalsFromContext(ctx)
|
||||||
|
|
||||||
|
checkUpdate()
|
||||||
|
|
||||||
console.Println("Version: " + Version)
|
console.Println("Version: " + Version)
|
||||||
console.Println("Release-Tag: " + ReleaseTag)
|
console.Println("Release-Tag: " + ReleaseTag)
|
||||||
console.Println("Commit-ID: " + CommitID)
|
console.Println("Commit-ID: " + CommitID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user