| 
									
										
										
										
											2015-12-08 06:12:47 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2017-01-19 04:24:34 +08:00
										 |  |  |  * Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc. | 
					
						
							| 
									
										
										
										
											2015-12-08 06:12:47 +08: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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2015-12-08 06:12:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-09 11:34:27 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2016-11-11 23:18:44 +08:00
										 |  |  | 	"crypto/x509" | 
					
						
							| 
									
										
										
										
											2017-01-23 16:32:55 +08:00
										 |  |  | 	"net/url" | 
					
						
							| 
									
										
										
										
											2016-12-10 16:42:22 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | 	"runtime" | 
					
						
							| 
									
										
										
										
											2016-12-10 16:42:22 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2016-09-10 06:33:35 +08:00
										 |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 10:18:22 +08:00
										 |  |  | 	humanize "github.com/dustin/go-humanize" | 
					
						
							| 
									
										
										
										
											2016-07-09 11:34:27 +08:00
										 |  |  | 	"github.com/fatih/color" | 
					
						
							| 
									
										
										
										
											2016-11-29 04:15:36 +08:00
										 |  |  | 	"github.com/minio/cli" | 
					
						
							|  |  |  | 	"github.com/minio/mc/pkg/console" | 
					
						
							| 
									
										
										
										
											2016-07-09 11:34:27 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/objcache" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
											  
											
												config/main: Re-write config files - add to new config v3
- New config format.
```
{
	"version": "3",
	"address": ":9000",
    "backend": {
          "type": "fs",
          "disk": "/path"
    },
	"credential": {
		"accessKey": "WLGDGYAQYIGI833EV05A",
		"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
	},
	"region": "us-east-1",
	"logger": {
		"file": {
			"enable": false,
			"fileName": "",
			"level": "error"
		},
		"syslog": {
			"enable": false,
			"address": "",
			"level": "debug"
		},
		"console": {
			"enable": true,
			"level": "fatal"
		}
	}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
											
										 
											2016-02-13 07:27:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-15 20:26:56 +08:00
										 |  |  | // Global constants for Minio.
 | 
					
						
							|  |  |  | const ( | 
					
						
							| 
									
										
										
										
											2016-10-25 04:44:15 +08:00
										 |  |  | 	minGoVersion = ">= 1.7" // Minio requires at least Go v1.7
 | 
					
						
							| 
									
										
										
										
											2015-12-08 06:12:47 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
											  
											
												config/main: Re-write config files - add to new config v3
- New config format.
```
{
	"version": "3",
	"address": ":9000",
    "backend": {
          "type": "fs",
          "disk": "/path"
    },
	"credential": {
		"accessKey": "WLGDGYAQYIGI833EV05A",
		"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
	},
	"region": "us-east-1",
	"logger": {
		"file": {
			"enable": false,
			"fileName": "",
			"level": "error"
		},
		"syslog": {
			"enable": false,
			"address": "",
			"level": "debug"
		},
		"console": {
			"enable": true,
			"level": "fatal"
		}
	}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
											
										 
											2016-02-13 07:27:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // minio configuration related constants.
 | 
					
						
							|  |  |  | const ( | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | 	globalMinioConfigVersion      = "13" | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | 	globalMinioConfigDir          = ".minio" | 
					
						
							|  |  |  | 	globalMinioCertsDir           = "certs" | 
					
						
							| 
									
										
										
										
											2016-11-11 23:18:44 +08:00
										 |  |  | 	globalMinioCertsCADir         = "CAs" | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | 	globalMinioCertFile           = "public.crt" | 
					
						
							|  |  |  | 	globalMinioKeyFile            = "private.key" | 
					
						
							|  |  |  | 	globalMinioConfigFile         = "config.json" | 
					
						
							| 
									
										
										
										
											2016-10-15 02:15:59 +08:00
										 |  |  | 	globalMinioCertExpireWarnDays = time.Hour * 24 * 30 // 30 days.
 | 
					
						
							| 
									
										
										
										
											2017-01-19 04:24:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	globalMinioDefaultRegion       = "us-east-1" | 
					
						
							|  |  |  | 	globalMinioDefaultOwnerID      = "minio" | 
					
						
							|  |  |  | 	globalMinioDefaultStorageClass = "STANDARD" | 
					
						
							|  |  |  | 	globalWindowsOSName            = "windows" | 
					
						
							| 
									
										
										
										
											2016-05-10 07:18:56 +08:00
										 |  |  | 	// Add new global values here.
 | 
					
						
							| 
									
										
											  
											
												config/main: Re-write config files - add to new config v3
- New config format.
```
{
	"version": "3",
	"address": ":9000",
    "backend": {
          "type": "fs",
          "disk": "/path"
    },
	"credential": {
		"accessKey": "WLGDGYAQYIGI833EV05A",
		"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
	},
	"region": "us-east-1",
	"logger": {
		"file": {
			"enable": false,
			"fileName": "",
			"level": "error"
		},
		"syslog": {
			"enable": false,
			"address": "",
			"level": "debug"
		},
		"console": {
			"enable": true,
			"level": "fatal"
		}
	}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
											
										 
											2016-02-13 07:27:10 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 12:13:20 +08:00
										 |  |  | const ( | 
					
						
							|  |  |  | 	// Limit fields size (except file) to 1Mib since Policy document
 | 
					
						
							|  |  |  | 	// can reach that size according to https://aws.amazon.com/articles/1434
 | 
					
						
							|  |  |  | 	maxFormFieldSize = int64(1 * humanize.MiByte) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// The maximum allowed difference between the request generation time and the server processing time
 | 
					
						
							|  |  |  | 	globalMaxSkewTime = 15 * time.Minute | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-25 08:20:49 +08:00
										 |  |  | var ( | 
					
						
							| 
									
										
										
										
											2016-11-29 04:15:36 +08:00
										 |  |  | 	globalQuiet     = false               // quiet flag set via command line.
 | 
					
						
							|  |  |  | 	globalConfigDir = mustGetConfigPath() // config-dir flag set via command line
 | 
					
						
							| 
									
										
										
										
											2016-11-24 09:27:42 +08:00
										 |  |  | 	// Add new global flags here.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-17 09:05:00 +08:00
										 |  |  | 	// Indicates if the running minio server is distributed setup.
 | 
					
						
							|  |  |  | 	globalIsDistXL = false | 
					
						
							| 
									
										
										
										
											2016-11-29 04:15:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 16:32:55 +08:00
										 |  |  | 	// Indicates if the running minio server is an erasure-code backend.
 | 
					
						
							|  |  |  | 	globalIsXL = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-10 16:42:22 +08:00
										 |  |  | 	// This flag is set to 'true' by default, it is set to `false`
 | 
					
						
							|  |  |  | 	// when MINIO_BROWSER env is set to 'off'.
 | 
					
						
							|  |  |  | 	globalIsBrowserEnabled = !strings.EqualFold(os.Getenv("MINIO_BROWSER"), "off") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-09 12:35:07 +08:00
										 |  |  | 	// Maximum cache size. Defaults to disabled.
 | 
					
						
							|  |  |  | 	// Caching is enabled only for RAM size > 8GiB.
 | 
					
						
							|  |  |  | 	globalMaxCacheSize = uint64(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-09 11:34:27 +08:00
										 |  |  | 	// Cache expiry.
 | 
					
						
							|  |  |  | 	globalCacheExpiry = objcache.DefaultExpiry | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 16:03:50 +08:00
										 |  |  | 	// Minio local server address (in `host:port` format)
 | 
					
						
							|  |  |  | 	globalMinioAddr = "" | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | 	// Minio default port, can be changed through command line.
 | 
					
						
							| 
									
										
										
										
											2016-10-27 18:30:52 +08:00
										 |  |  | 	globalMinioPort = "9000" | 
					
						
							| 
									
										
										
										
											2016-10-19 03:49:24 +08:00
										 |  |  | 	// Holds the host that was passed using --address
 | 
					
						
							|  |  |  | 	globalMinioHost = "" | 
					
						
							| 
									
										
										
										
											2016-12-29 19:13:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	// Holds the list of API endpoints for a given server.
 | 
					
						
							|  |  |  | 	globalAPIEndpoints = []string{} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 16:03:50 +08:00
										 |  |  | 	// Peer communication struct
 | 
					
						
							|  |  |  | 	globalS3Peers = s3Peers{} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-11 23:18:44 +08:00
										 |  |  | 	// CA root certificates, a nil value means system certs pool will be used
 | 
					
						
							|  |  |  | 	globalRootCAs *x509.CertPool | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-12 05:59:51 +08:00
										 |  |  | 	// IsSSL indicates if the server is configured with SSL.
 | 
					
						
							|  |  |  | 	globalIsSSL bool | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 19:13:51 +08:00
										 |  |  | 	// List of admin peers.
 | 
					
						
							| 
									
										
										
										
											2016-12-16 14:26:15 +08:00
										 |  |  | 	globalAdminPeers = adminPeers{} | 
					
						
							| 
									
										
										
										
											2016-12-29 19:13:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 06:22:10 +08:00
										 |  |  | 	// Minio server user agent string.
 | 
					
						
							|  |  |  | 	globalServerUserAgent = "Minio/" + ReleaseTag + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 06:25:59 +08:00
										 |  |  | 	// Access key passed from the environment
 | 
					
						
							|  |  |  | 	globalEnvAccessKey = os.Getenv("MINIO_ACCESS_KEY") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Secret key passed from the environment
 | 
					
						
							|  |  |  | 	globalEnvSecretKey = os.Getenv("MINIO_SECRET_KEY") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 16:32:55 +08:00
										 |  |  | 	// url.URL endpoints of disks that belong to the object storage.
 | 
					
						
							|  |  |  | 	globalEndpoints = []*url.URL{} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-26 18:18:07 +08:00
										 |  |  | 	// Add new variable global values here.
 | 
					
						
							| 
									
										
										
										
											2016-03-25 08:20:49 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-29 03:02:22 +08:00
										 |  |  | var ( | 
					
						
							| 
									
										
										
										
											2016-10-22 13:56:27 +08:00
										 |  |  | 	// Keeps the connection active by waiting for following amount of time.
 | 
					
						
							|  |  |  | 	// Primarily used in ListenBucketNotification.
 | 
					
						
							|  |  |  | 	globalSNSConnAlive = 5 * time.Second | 
					
						
							| 
									
										
										
										
											2016-09-10 06:33:35 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												config/main: Re-write config files - add to new config v3
- New config format.
```
{
	"version": "3",
	"address": ":9000",
    "backend": {
          "type": "fs",
          "disk": "/path"
    },
	"credential": {
		"accessKey": "WLGDGYAQYIGI833EV05A",
		"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
	},
	"region": "us-east-1",
	"logger": {
		"file": {
			"enable": false,
			"fileName": "",
			"level": "error"
		},
		"syslog": {
			"enable": false,
			"address": "",
			"level": "debug"
		},
		"console": {
			"enable": true,
			"level": "fatal"
		}
	}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
											
										 
											2016-02-13 07:27:10 +08:00
										 |  |  | // global colors.
 | 
					
						
							|  |  |  | var ( | 
					
						
							| 
									
										
										
										
											2017-01-19 04:24:34 +08:00
										 |  |  | 	colorBold = color.New(color.Bold).SprintFunc() | 
					
						
							|  |  |  | 	colorBlue = color.New(color.FgBlue).SprintfFunc() | 
					
						
							| 
									
										
											  
											
												config/main: Re-write config files - add to new config v3
- New config format.
```
{
	"version": "3",
	"address": ":9000",
    "backend": {
          "type": "fs",
          "disk": "/path"
    },
	"credential": {
		"accessKey": "WLGDGYAQYIGI833EV05A",
		"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
	},
	"region": "us-east-1",
	"logger": {
		"file": {
			"enable": false,
			"fileName": "",
			"level": "error"
		},
		"syslog": {
			"enable": false,
			"address": "",
			"level": "debug"
		},
		"console": {
			"enable": true,
			"level": "fatal"
		}
	}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
											
										 
											2016-02-13 07:27:10 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-11-29 04:15:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Parse command arguments and set global variables accordingly
 | 
					
						
							|  |  |  | func setGlobalsFromContext(c *cli.Context) { | 
					
						
							|  |  |  | 	// Set config dir
 | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case c.IsSet("config-dir"): | 
					
						
							|  |  |  | 		globalConfigDir = c.String("config-dir") | 
					
						
							|  |  |  | 	case c.GlobalIsSet("config-dir"): | 
					
						
							|  |  |  | 		globalConfigDir = c.GlobalString("config-dir") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if globalConfigDir == "" { | 
					
						
							|  |  |  | 		console.Fatalf("Unable to get config file. Config directory is empty.") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-16 08:53:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-29 04:15:36 +08:00
										 |  |  | 	// Set global quiet flag.
 | 
					
						
							|  |  |  | 	globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet") | 
					
						
							|  |  |  | } |