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-12 18:27:10 -05:00
|
|
|
|
/*
|
2017-01-18 15:24:34 -05:00
|
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
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-12 18:27:10 -05: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-18 19:23:42 -04:00
|
|
|
|
package cmd
|
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-12 18:27:10 -05:00
|
|
|
|
|
|
|
|
|
import (
|
2017-03-01 12:17:04 -05:00
|
|
|
|
"errors"
|
2017-03-16 14:06:17 -04:00
|
|
|
|
"fmt"
|
2017-03-15 19:30:34 -04:00
|
|
|
|
"io/ioutil"
|
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-12 18:27:10 -05:00
|
|
|
|
"sync"
|
|
|
|
|
|
2017-10-31 14:54:32 -04:00
|
|
|
|
"github.com/minio/minio/pkg/auth"
|
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-12 18:27:10 -05:00
|
|
|
|
"github.com/minio/minio/pkg/quick"
|
2017-03-15 19:30:34 -04:00
|
|
|
|
"github.com/tidwall/gjson"
|
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-12 18:27:10 -05:00
|
|
|
|
)
|
|
|
|
|
|
2017-11-29 16:12:47 -05:00
|
|
|
|
// Steps to move from version N to version N+1
|
|
|
|
|
// 1. Add new struct serverConfigVN+1 in config-versions.go
|
2017-12-18 00:00:12 -05:00
|
|
|
|
// 2. Set serverConfigVersion to "N+1"
|
|
|
|
|
// 3. Set serverConfig to serverConfigVN+1
|
2017-11-29 16:12:47 -05:00
|
|
|
|
// 4. Add new migration function (ex. func migrateVNToVN+1()) in config-migrate.go
|
|
|
|
|
// 5. Call migrateVNToVN+1() from migrateConfig() in config-migrate.go
|
|
|
|
|
// 6. Make changes in config-current_test.go for any test change
|
|
|
|
|
|
2017-03-27 14:27:25 -04:00
|
|
|
|
// Config version
|
2017-12-22 06:28:13 -05:00
|
|
|
|
const serverConfigVersion = "22"
|
2017-11-29 16:12:47 -05:00
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
type serverConfig = serverConfigV22
|
2017-03-27 14:27:25 -04:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
var (
|
2017-11-29 16:12:47 -05:00
|
|
|
|
// globalServerConfig server config.
|
|
|
|
|
globalServerConfig *serverConfig
|
|
|
|
|
globalServerConfigMu sync.RWMutex
|
2017-03-31 01:26:24 -04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GetVersion get current config version.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetVersion() string {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return s.Version
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// SetRegion set a new region.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) SetRegion(region string) {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// Save new region.
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Region = region
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetRegion get current region.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetRegion() string {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return s.Region
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 02:18:29 -05:00
|
|
|
|
// SetCredential sets new credential and returns the previous credential.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) SetCredential(creds auth.Credentials) (prevCred auth.Credentials) {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// Save previous credential.
|
|
|
|
|
prevCred = s.Credential
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// Set updated credential.
|
|
|
|
|
s.Credential = creds
|
2017-08-08 15:14:32 -04:00
|
|
|
|
|
|
|
|
|
// Return previous credential.
|
|
|
|
|
return prevCred
|
2017-03-31 01:26:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCredentials get current credentials.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetCredential() auth.Credentials {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return s.Credential
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetBrowser set if browser is enabled.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) SetBrowser(b bool) {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
|
|
|
|
// Set the new value.
|
|
|
|
|
s.Browser = BrowserFlag(b)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
func (s *serverConfig) SetStorageClass(standardClass, rrsClass storageClass) {
|
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
2018-01-09 01:26:13 -05:00
|
|
|
|
s.StorageClass.Standard = standardClass
|
|
|
|
|
s.StorageClass.RRS = rrsClass
|
2017-12-22 06:28:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-28 03:49:45 -05:00
|
|
|
|
// GetStorageClass reads storage class fields from current config, parses and validates it.
|
|
|
|
|
// It returns the standard and reduced redundancy storage class struct
|
2018-01-09 01:26:13 -05:00
|
|
|
|
func (s *serverConfig) GetStorageClass() (storageClass, storageClass) {
|
2017-12-22 06:28:13 -05:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
var err error
|
2018-01-09 01:26:13 -05:00
|
|
|
|
// Storage Class from config.json is already parsed and stored in s.StorageClass
|
|
|
|
|
// Now validate the storage class fields
|
|
|
|
|
ssc := s.StorageClass.Standard
|
|
|
|
|
rrsc := s.StorageClass.RRS
|
2017-12-22 06:28:13 -05:00
|
|
|
|
|
|
|
|
|
if rrsc.Scheme != "" {
|
2017-12-28 03:49:45 -05:00
|
|
|
|
err = validateRRSParity(rrsc.Parity, ssc.Parity)
|
2018-01-09 01:26:13 -05:00
|
|
|
|
fatalIf(err, "Invalid value %s:%d set in config.json", rrsc.Scheme, rrsc.Parity)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
globalIsStorageClass = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ssc.Scheme != "" {
|
2017-12-28 03:49:45 -05:00
|
|
|
|
err = validateSSParity(ssc.Parity, rrsc.Parity)
|
2018-01-09 01:26:13 -05:00
|
|
|
|
fatalIf(err, "Invalid value %s:%d set in config.json", ssc.Scheme, ssc.Parity)
|
2017-12-22 06:28:13 -05:00
|
|
|
|
globalIsStorageClass = true
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 01:26:13 -05:00
|
|
|
|
return s.StorageClass.Standard, s.StorageClass.RRS
|
2017-12-22 06:28:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// GetCredentials get current credentials.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetBrowser() bool {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return bool(s.Browser)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save config.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) Save() error {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
// Save config file.
|
|
|
|
|
return quick.Save(getConfigFile(), s)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func newServerConfig() *serverConfig {
|
|
|
|
|
srvCfg := &serverConfig{
|
2018-01-09 01:26:13 -05:00
|
|
|
|
Version: serverConfigVersion,
|
|
|
|
|
Credential: auth.MustGetNewCredentials(),
|
|
|
|
|
Region: globalMinioDefaultRegion,
|
|
|
|
|
Browser: true,
|
|
|
|
|
StorageClass: storageClassConfig{},
|
|
|
|
|
Notify: ¬ifier{},
|
2017-02-27 17:59:53 -05:00
|
|
|
|
}
|
2017-03-26 15:00:27 -04:00
|
|
|
|
|
2017-02-07 15:51:43 -05:00
|
|
|
|
// Make sure to initialize notification configs.
|
|
|
|
|
srvCfg.Notify.AMQP = make(map[string]amqpNotify)
|
|
|
|
|
srvCfg.Notify.AMQP["1"] = amqpNotify{}
|
2017-06-14 20:27:03 -04:00
|
|
|
|
srvCfg.Notify.MQTT = make(map[string]mqttNotify)
|
|
|
|
|
srvCfg.Notify.MQTT["1"] = mqttNotify{}
|
2017-02-07 15:51:43 -05:00
|
|
|
|
srvCfg.Notify.ElasticSearch = make(map[string]elasticSearchNotify)
|
|
|
|
|
srvCfg.Notify.ElasticSearch["1"] = elasticSearchNotify{}
|
|
|
|
|
srvCfg.Notify.Redis = make(map[string]redisNotify)
|
|
|
|
|
srvCfg.Notify.Redis["1"] = redisNotify{}
|
|
|
|
|
srvCfg.Notify.NATS = make(map[string]natsNotify)
|
|
|
|
|
srvCfg.Notify.NATS["1"] = natsNotify{}
|
|
|
|
|
srvCfg.Notify.PostgreSQL = make(map[string]postgreSQLNotify)
|
|
|
|
|
srvCfg.Notify.PostgreSQL["1"] = postgreSQLNotify{}
|
2017-03-17 12:29:17 -04:00
|
|
|
|
srvCfg.Notify.MySQL = make(map[string]mySQLNotify)
|
|
|
|
|
srvCfg.Notify.MySQL["1"] = mySQLNotify{}
|
2017-02-07 15:51:43 -05:00
|
|
|
|
srvCfg.Notify.Kafka = make(map[string]kafkaNotify)
|
|
|
|
|
srvCfg.Notify.Kafka["1"] = kafkaNotify{}
|
|
|
|
|
srvCfg.Notify.Webhook = make(map[string]webhookNotify)
|
|
|
|
|
srvCfg.Notify.Webhook["1"] = webhookNotify{}
|
|
|
|
|
|
2017-03-01 12:17:04 -05:00
|
|
|
|
return srvCfg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// newConfig - initialize a new server config, saves env parameters if
|
|
|
|
|
// found, otherwise use default parameters
|
2017-03-30 14:21:19 -04:00
|
|
|
|
func newConfig() error {
|
2017-03-01 12:17:04 -05:00
|
|
|
|
// Initialize server config.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
srvCfg := newServerConfig()
|
2017-03-01 12:17:04 -05:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// If env is set override the credentials from config file.
|
2017-03-01 12:17:04 -05:00
|
|
|
|
if globalIsEnvCreds {
|
2017-03-30 14:21:19 -04:00
|
|
|
|
srvCfg.SetCredential(globalActiveCred)
|
2017-03-01 12:17:04 -05:00
|
|
|
|
}
|
2017-03-31 06:34:26 -04:00
|
|
|
|
|
2017-03-01 12:17:04 -05:00
|
|
|
|
if globalIsEnvBrowser {
|
2017-03-30 14:21:19 -04:00
|
|
|
|
srvCfg.SetBrowser(globalIsBrowserEnabled)
|
2017-03-01 12:17:04 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-09 13:44:10 -04:00
|
|
|
|
if globalIsEnvRegion {
|
|
|
|
|
srvCfg.SetRegion(globalServerRegion)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
|
if globalIsEnvDomainName {
|
|
|
|
|
srvCfg.Domain = globalDomainName
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
if globalIsStorageClass {
|
|
|
|
|
srvCfg.SetStorageClass(globalStandardStorageClass, globalRRStorageClass)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 15:51:43 -05:00
|
|
|
|
// hold the mutex lock before a new config is assigned.
|
|
|
|
|
// Save the new config globally.
|
|
|
|
|
// unlock the mutex.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerConfigMu.Lock()
|
|
|
|
|
globalServerConfig = srvCfg
|
|
|
|
|
globalServerConfigMu.Unlock()
|
2017-02-07 15:51:43 -05:00
|
|
|
|
|
|
|
|
|
// Save config into file.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
return globalServerConfig.Save()
|
2017-02-07 15:51:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 19:30:34 -04:00
|
|
|
|
// doCheckDupJSONKeys recursively detects duplicate json keys
|
|
|
|
|
func doCheckDupJSONKeys(key, value gjson.Result) error {
|
|
|
|
|
// Key occurrences map of the current scope to count
|
|
|
|
|
// if there is any duplicated json key.
|
|
|
|
|
keysOcc := make(map[string]int)
|
|
|
|
|
|
|
|
|
|
// Holds the found error
|
|
|
|
|
var checkErr error
|
|
|
|
|
|
|
|
|
|
// Iterate over keys in the current json scope
|
|
|
|
|
value.ForEach(func(k, v gjson.Result) bool {
|
|
|
|
|
// If current key is not null, check if its
|
|
|
|
|
// value contains some duplicated keys.
|
|
|
|
|
if k.Type != gjson.Null {
|
|
|
|
|
keysOcc[k.String()]++
|
|
|
|
|
checkErr = doCheckDupJSONKeys(k, v)
|
|
|
|
|
}
|
|
|
|
|
return checkErr == nil
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Check found err
|
|
|
|
|
if checkErr != nil {
|
|
|
|
|
return errors.New(key.String() + " => " + checkErr.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for duplicated keys
|
|
|
|
|
for k, v := range keysOcc {
|
|
|
|
|
if v > 1 {
|
|
|
|
|
return errors.New(key.String() + " => `" + k + "` entry is duplicated")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check recursively if a key is duplicated in the same json scope
|
|
|
|
|
// e.g.:
|
|
|
|
|
// `{ "key" : { "key" ..` is accepted
|
|
|
|
|
// `{ "key" : { "subkey" : "val1", "subkey": "val2" ..` throws subkey duplicated error
|
|
|
|
|
func checkDupJSONKeys(json string) error {
|
|
|
|
|
// Parse config with gjson library
|
|
|
|
|
config := gjson.Parse(json)
|
|
|
|
|
|
|
|
|
|
// Create a fake rootKey since root json doesn't seem to have representation
|
|
|
|
|
// in gjson library.
|
|
|
|
|
rootKey := gjson.Result{Type: gjson.String, Str: minioConfigFile}
|
|
|
|
|
|
|
|
|
|
// Check if loaded json contains any duplicated keys
|
|
|
|
|
return doCheckDupJSONKeys(rootKey, config)
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// getValidConfig - returns valid server configuration
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func getValidConfig() (*serverConfig, error) {
|
|
|
|
|
srvCfg := &serverConfig{
|
2017-03-26 15:00:27 -04:00
|
|
|
|
Region: globalMinioDefaultRegion,
|
|
|
|
|
Browser: true,
|
|
|
|
|
}
|
2017-03-15 19:30:34 -04:00
|
|
|
|
|
2017-03-26 15:00:27 -04:00
|
|
|
|
configFile := getConfigFile()
|
2017-03-22 13:23:25 -04:00
|
|
|
|
if _, err := quick.Load(configFile, srvCfg); err != nil {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 16:12:47 -05:00
|
|
|
|
if srvCfg.Version != serverConfigVersion {
|
|
|
|
|
return nil, fmt.Errorf("configuration version mismatch. Expected: ‘%s’, Got: ‘%s’", serverConfigVersion, srvCfg.Version)
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load config file json and check for duplication json keys
|
|
|
|
|
jsonBytes, err := ioutil.ReadFile(configFile)
|
|
|
|
|
if err != nil {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if err = checkDupJSONKeys(string(jsonBytes)); err != nil {
|
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 19:11:58 -04:00
|
|
|
|
// Validate credential fields only when
|
|
|
|
|
// they are not set via the environment
|
2017-03-31 01:26:24 -04:00
|
|
|
|
|
|
|
|
|
// Error out if global is env credential is not set and config has invalid credential
|
|
|
|
|
if !globalIsEnvCreds && !srvCfg.Credential.IsValid() {
|
|
|
|
|
return nil, errors.New("invalid credential in config file " + configFile)
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate notify field
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if err = srvCfg.Notify.Validate(); err != nil {
|
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return srvCfg, nil
|
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-12 18:27:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// loadConfig - loads a new config from disk, overrides params from env
|
|
|
|
|
// if found and valid
|
|
|
|
|
func loadConfig() error {
|
|
|
|
|
srvCfg, err := getValidConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2017-03-16 14:06:17 -04:00
|
|
|
|
}
|
2016-12-07 06:41:54 -05:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// If env is set override the credentials from config file.
|
|
|
|
|
if globalIsEnvCreds {
|
|
|
|
|
srvCfg.SetCredential(globalActiveCred)
|
|
|
|
|
}
|
2017-04-09 13:44:10 -04:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if globalIsEnvBrowser {
|
|
|
|
|
srvCfg.SetBrowser(globalIsBrowserEnabled)
|
|
|
|
|
}
|
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-12 18:27:10 -05:00
|
|
|
|
|
2017-04-09 13:44:10 -04:00
|
|
|
|
if globalIsEnvRegion {
|
|
|
|
|
srvCfg.SetRegion(globalServerRegion)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
|
if globalIsEnvDomainName {
|
|
|
|
|
srvCfg.Domain = globalDomainName
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
if globalIsStorageClass {
|
|
|
|
|
srvCfg.SetStorageClass(globalStandardStorageClass, globalRRStorageClass)
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// hold the mutex lock before a new config is assigned.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerConfigMu.Lock()
|
|
|
|
|
globalServerConfig = srvCfg
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if !globalIsEnvCreds {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalActiveCred = globalServerConfig.GetCredential()
|
2017-03-31 01:26:24 -04:00
|
|
|
|
}
|
|
|
|
|
if !globalIsEnvBrowser {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalIsBrowserEnabled = globalServerConfig.GetBrowser()
|
2017-03-31 01:26:24 -04:00
|
|
|
|
}
|
2017-04-09 13:44:10 -04:00
|
|
|
|
if !globalIsEnvRegion {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerRegion = globalServerConfig.GetRegion()
|
2017-04-09 13:44:10 -04:00
|
|
|
|
}
|
2017-11-14 19:56:24 -05:00
|
|
|
|
if !globalIsEnvDomainName {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalDomainName = globalServerConfig.Domain
|
2017-11-14 19:56:24 -05:00
|
|
|
|
}
|
2017-12-22 06:28:13 -05:00
|
|
|
|
if !globalIsStorageClass {
|
|
|
|
|
globalStandardStorageClass, globalRRStorageClass = globalServerConfig.GetStorageClass()
|
|
|
|
|
}
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerConfigMu.Unlock()
|
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-12 18:27:10 -05:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return nil
|
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-12 18:27:10 -05:00
|
|
|
|
}
|