mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Merge initConfig logic to ConfigSys (#6312)
This commit is contained in:
parent
bf14e5ce1b
commit
7d7e21aebb
@ -8,6 +8,13 @@ dist: trusty
|
|||||||
|
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
|
# this ensures PRs based on a local branch are not built twice
|
||||||
|
# the downside is that a PR targeting a different branch is not built
|
||||||
|
# but as a workaround you can add the branch to this list
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: linux
|
- os: linux
|
||||||
|
@ -64,6 +64,12 @@ func (s *serverConfig) SetRegion(region string) {
|
|||||||
|
|
||||||
// GetRegion get current region.
|
// GetRegion get current region.
|
||||||
func (s *serverConfig) GetRegion() string {
|
func (s *serverConfig) GetRegion() string {
|
||||||
|
if globalIsEnvRegion {
|
||||||
|
return globalServerRegion
|
||||||
|
}
|
||||||
|
if s == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return s.Region
|
return s.Region
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,16 +117,34 @@ func (s *serverConfig) SetStorageClass(standardClass, rrsClass storageClass) {
|
|||||||
// GetStorageClass reads storage class fields from current config.
|
// GetStorageClass reads storage class fields from current config.
|
||||||
// It returns the standard and reduced redundancy storage class struct
|
// It returns the standard and reduced redundancy storage class struct
|
||||||
func (s *serverConfig) GetStorageClass() (storageClass, storageClass) {
|
func (s *serverConfig) GetStorageClass() (storageClass, storageClass) {
|
||||||
|
if globalIsStorageClass {
|
||||||
|
return globalStandardStorageClass, globalRRStorageClass
|
||||||
|
}
|
||||||
|
if s == nil {
|
||||||
|
return storageClass{}, storageClass{}
|
||||||
|
}
|
||||||
return s.StorageClass.Standard, s.StorageClass.RRS
|
return s.StorageClass.Standard, s.StorageClass.RRS
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBrowser get current credentials.
|
// GetBrowser get current credentials.
|
||||||
func (s *serverConfig) GetBrowser() bool {
|
func (s *serverConfig) GetBrowser() bool {
|
||||||
|
if globalIsEnvWORM {
|
||||||
|
return globalWORMEnabled
|
||||||
|
}
|
||||||
|
if s == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return bool(s.Browser)
|
return bool(s.Browser)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWorm get current credentials.
|
// GetWorm get current credentials.
|
||||||
func (s *serverConfig) GetWorm() bool {
|
func (s *serverConfig) GetWorm() bool {
|
||||||
|
if globalIsEnvBrowser {
|
||||||
|
return globalIsBrowserEnabled
|
||||||
|
}
|
||||||
|
if s == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return bool(s.Worm)
|
return bool(s.Worm)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,10 +158,24 @@ func (s *serverConfig) SetCacheConfig(drives, exclude []string, expiry int, maxu
|
|||||||
|
|
||||||
// GetCacheConfig gets the current cache config
|
// GetCacheConfig gets the current cache config
|
||||||
func (s *serverConfig) GetCacheConfig() CacheConfig {
|
func (s *serverConfig) GetCacheConfig() CacheConfig {
|
||||||
|
if globalIsDiskCacheEnabled {
|
||||||
|
return CacheConfig{
|
||||||
|
Drives: globalCacheDrives,
|
||||||
|
Exclude: globalCacheExcludes,
|
||||||
|
Expiry: globalCacheExpiry,
|
||||||
|
MaxUse: globalCacheMaxUse,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if s == nil {
|
||||||
|
return CacheConfig{}
|
||||||
|
}
|
||||||
return s.Cache
|
return s.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serverConfig) Validate() error {
|
func (s *serverConfig) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if s.Version != serverConfigVersion {
|
if s.Version != serverConfigVersion {
|
||||||
return fmt.Errorf("configuration version mismatch. Expected: ‘%s’, Got: ‘%s’", serverConfigVersion, s.Version)
|
return fmt.Errorf("configuration version mismatch. Expected: ‘%s’, Got: ‘%s’", serverConfigVersion, s.Version)
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func TestServerConfigWithEnvs(t *testing.T) {
|
|||||||
serverHandleEnvVars()
|
serverHandleEnvVars()
|
||||||
|
|
||||||
// Init config
|
// Init config
|
||||||
initConfig()
|
initConfig(objLayer)
|
||||||
|
|
||||||
// Check if serverConfig has
|
// Check if serverConfig has
|
||||||
if globalServerConfig.GetBrowser() {
|
if globalServerConfig.GetBrowser() {
|
||||||
|
@ -2411,18 +2411,6 @@ func migrateV27ToV28() error {
|
|||||||
|
|
||||||
// Migrates '.minio.sys/config.json' v27 to v28.
|
// Migrates '.minio.sys/config.json' v27 to v28.
|
||||||
func migrateMinioSysConfig(objAPI ObjectLayer) error {
|
func migrateMinioSysConfig(objAPI ObjectLayer) error {
|
||||||
// Construct path to config.json for the given bucket.
|
|
||||||
configFile := path.Join(bucketConfigPrefix, minioConfigFile)
|
|
||||||
transactionConfigFile := configFile + ".transaction"
|
|
||||||
|
|
||||||
// As object layer's GetObject() and PutObject() take respective lock on minioMetaBucket
|
|
||||||
// and configFile, take a transaction lock to avoid race.
|
|
||||||
objLock := globalNSMutex.NewNSLock(minioMetaBucket, transactionConfigFile)
|
|
||||||
if err := objLock.GetLock(globalOperationTimeout); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer objLock.Unlock()
|
|
||||||
|
|
||||||
return migrateV27ToV28MinioSys(objAPI)
|
return migrateV27ToV28MinioSys(objAPI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func (sys *ConfigSys) Init(objAPI ObjectLayer) error {
|
|||||||
if objAPI == nil {
|
if objAPI == nil {
|
||||||
return errInvalidArgument
|
return errInvalidArgument
|
||||||
}
|
}
|
||||||
return loadConfig(objAPI)
|
return initConfig(objAPI)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigSys - creates new config system object.
|
// NewConfigSys - creates new config system object.
|
||||||
@ -201,20 +201,8 @@ func NewConfigSys() *ConfigSys {
|
|||||||
return &ConfigSys{}
|
return &ConfigSys{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/minio.json'
|
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/config.json'
|
||||||
func migrateConfigToMinioSys() error {
|
func migrateConfigToMinioSys() error {
|
||||||
// Construct path to config.json for the given bucket.
|
|
||||||
configFile := path.Join(bucketConfigPrefix, minioConfigFile)
|
|
||||||
transactionConfigFile := configFile + ".transaction"
|
|
||||||
|
|
||||||
// As object layer's GetObject() and PutObject() take respective lock on minioMetaBucket
|
|
||||||
// and configFile, take a transaction lock to avoid race.
|
|
||||||
objLock := globalNSMutex.NewNSLock(minioMetaBucket, transactionConfigFile)
|
|
||||||
if err := objLock.GetLock(globalOperationTimeout); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer objLock.Unlock()
|
|
||||||
|
|
||||||
// Verify if backend already has the file.
|
// Verify if backend already has the file.
|
||||||
if err := checkServerConfig(context.Background(), newObjectLayerFn()); err != errConfigNotFound {
|
if err := checkServerConfig(context.Background(), newObjectLayerFn()); err != errConfigNotFound {
|
||||||
return err
|
return err
|
||||||
@ -229,39 +217,45 @@ func migrateConfigToMinioSys() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize and load config from remote etcd or local config directory
|
// Initialize and load config from remote etcd or local config directory
|
||||||
func initConfig() {
|
func initConfig(objAPI ObjectLayer) error {
|
||||||
|
if objAPI == nil {
|
||||||
|
return errServerNotInitialized
|
||||||
|
}
|
||||||
|
|
||||||
if globalEtcdClient != nil {
|
if globalEtcdClient != nil {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||||
resp, err := globalEtcdClient.Get(ctx, getConfigFile())
|
resp, err := globalEtcdClient.Get(ctx, getConfigFile())
|
||||||
cancel()
|
cancel()
|
||||||
if err == nil && resp.Count > 0 {
|
if err == nil && resp.Count > 0 {
|
||||||
logger.FatalIf(migrateConfig(), "Config migration failed")
|
return migrateConfig()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if isFile(getConfigFile()) {
|
if isFile(getConfigFile()) {
|
||||||
logger.FatalIf(migrateConfig(), "Config migration failed")
|
if err := migrateConfig(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/config.json'
|
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/config.json'
|
||||||
if err := migrateConfigToMinioSys(); err != nil {
|
if err := migrateConfigToMinioSys(); err != nil {
|
||||||
logger.Fatal(err, "Unable to migrate 'config.json' to '.minio.sys/config/config.json'")
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
objAPI := newObjectLayerFn()
|
|
||||||
if objAPI == nil {
|
|
||||||
logger.FatalIf(errServerNotInitialized, "Server is not initialized yet unable to proceed")
|
|
||||||
}
|
|
||||||
if err := checkServerConfig(context.Background(), objAPI); err != nil {
|
if err := checkServerConfig(context.Background(), objAPI); err != nil {
|
||||||
if err == errConfigNotFound {
|
if err == errConfigNotFound {
|
||||||
// Config file does not exist, we create it fresh and return upon success.
|
// Config file does not exist, we create it fresh and return upon success.
|
||||||
logger.FatalIf(newConfig(objAPI), "Unable to initialize minio config for the first time")
|
if err = newConfig(objAPI); err != nil {
|
||||||
logger.Info("Created minio configuration file successfully at " + getConfigDir())
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.FatalIf(err, "Unable to load the configuration file")
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.FatalIf(migrateMinioSysConfig(objAPI), "Config migration failed for minio.sys config")
|
if err := migrateMinioSysConfig(objAPI); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
logger.FatalIf(loadConfig(objAPI), "Unable to load the configuration file")
|
return loadConfig(objAPI)
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,14 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
|
|||||||
globalServerConfig = srvCfg
|
globalServerConfig = srvCfg
|
||||||
globalServerConfigMu.Unlock()
|
globalServerConfigMu.Unlock()
|
||||||
|
|
||||||
|
var cacheConfig = globalServerConfig.GetCacheConfig()
|
||||||
|
if len(cacheConfig.Drives) > 0 {
|
||||||
|
var err error
|
||||||
|
// initialize the new disk cache objects.
|
||||||
|
globalCacheObjectAPI, err = newServerCacheObjects(cacheConfig)
|
||||||
|
logger.FatalIf(err, "Unable to initialize disk caching")
|
||||||
|
}
|
||||||
|
|
||||||
// Check and load SSL certificates.
|
// Check and load SSL certificates.
|
||||||
var err error
|
var err error
|
||||||
globalPublicCerts, globalRootCAs, globalTLSCerts, globalIsSSL, err = getSSLConfig()
|
globalPublicCerts, globalRootCAs, globalTLSCerts, globalIsSSL, err = getSSLConfig()
|
||||||
|
@ -91,7 +91,7 @@ ENVIRONMENT VARIABLES:
|
|||||||
MINIO_DOMAIN: To enable bucket DNS requests, set this value to Minio host domain name.
|
MINIO_DOMAIN: To enable bucket DNS requests, set this value to Minio host domain name.
|
||||||
MINIO_PUBLIC_IPS: To enable bucket DNS requests, set this value to list of Minio host public IP(s) delimited by ",".
|
MINIO_PUBLIC_IPS: To enable bucket DNS requests, set this value to list of Minio host public IP(s) delimited by ",".
|
||||||
MINIO_ETCD_ENDPOINTS: To enable bucket DNS requests, set this value to list of etcd endpoints delimited by ",".
|
MINIO_ETCD_ENDPOINTS: To enable bucket DNS requests, set this value to list of etcd endpoints delimited by ",".
|
||||||
|
|
||||||
KMS:
|
KMS:
|
||||||
MINIO_SSE_VAULT_ENDPOINT: To enable Vault as KMS,set this value to Vault endpoint.
|
MINIO_SSE_VAULT_ENDPOINT: To enable Vault as KMS,set this value to Vault endpoint.
|
||||||
MINIO_SSE_VAULT_APPROLE_ID: To enable Vault as KMS,set this value to Vault AppRole ID.
|
MINIO_SSE_VAULT_APPROLE_ID: To enable Vault as KMS,set this value to Vault AppRole ID.
|
||||||
@ -123,7 +123,7 @@ EXAMPLES:
|
|||||||
$ export MINIO_CACHE_EXPIRY=40
|
$ export MINIO_CACHE_EXPIRY=40
|
||||||
$ export MINIO_CACHE_MAXUSE=80
|
$ export MINIO_CACHE_MAXUSE=80
|
||||||
$ {{.HelpName}} /home/shared
|
$ {{.HelpName}} /home/shared
|
||||||
|
|
||||||
7. Start minio server with KMS enabled.
|
7. Start minio server with KMS enabled.
|
||||||
$ export MINIO_SSE_VAULT_APPROLE_ID=9b56cc08-8258-45d5-24a3-679876769126
|
$ export MINIO_SSE_VAULT_APPROLE_ID=9b56cc08-8258-45d5-24a3-679876769126
|
||||||
$ export MINIO_SSE_VAULT_APPROLE_SECRET=4e30c52f-13e4-a6f5-0763-d50e8cb4321f
|
$ export MINIO_SSE_VAULT_APPROLE_SECRET=4e30c52f-13e4-a6f5-0763-d50e8cb4321f
|
||||||
@ -322,8 +322,13 @@ func serverMain(ctx *cli.Context) {
|
|||||||
initFederatorBackend(newObject)
|
initFederatorBackend(newObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize server config.
|
// Create a new config system.
|
||||||
initConfig()
|
globalConfigSys = NewConfigSys()
|
||||||
|
|
||||||
|
// Initialize config system.
|
||||||
|
if err = globalConfigSys.Init(newObjectLayerFn()); err != nil {
|
||||||
|
logger.Fatal(err, "Unable to initialize config system")
|
||||||
|
}
|
||||||
|
|
||||||
// Load logger subsystem
|
// Load logger subsystem
|
||||||
loadLoggers()
|
loadLoggers()
|
||||||
@ -338,14 +343,6 @@ func serverMain(ctx *cli.Context) {
|
|||||||
// Re-enable logging
|
// Re-enable logging
|
||||||
logger.Disable = false
|
logger.Disable = false
|
||||||
|
|
||||||
// Create a new config system.
|
|
||||||
globalConfigSys = NewConfigSys()
|
|
||||||
|
|
||||||
// Initialize config system.
|
|
||||||
if err := globalConfigSys.Init(newObjectLayerFn()); err != nil {
|
|
||||||
logger.Fatal(err, "Unable to initialize config system")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new policy system.
|
// Create new policy system.
|
||||||
globalPolicySys = NewPolicySys()
|
globalPolicySys = NewPolicySys()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user