github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/cmd/mattermost/commands/init.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package commands 5 6 import ( 7 "github.com/spf13/cobra" 8 9 "github.com/mattermost/mattermost-server/v5/app" 10 "github.com/mattermost/mattermost-server/v5/config" 11 "github.com/mattermost/mattermost-server/v5/model" 12 "github.com/mattermost/mattermost-server/v5/utils" 13 ) 14 15 func initDBCommandContextCobra(command *cobra.Command, readOnlyConfigStore bool) (*app.App, error) { 16 a, err := initDBCommandContext(getConfigDSN(command, config.GetEnvironment()), readOnlyConfigStore) 17 if err != nil { 18 // Returning an error just prints the usage message, so actually panic 19 panic(err) 20 } 21 22 a.InitPlugins(*a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory) 23 a.DoAppMigrations() 24 25 return a, nil 26 } 27 28 func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) { 29 return initDBCommandContextCobra(command, true) 30 } 31 32 func InitDBCommandContextCobraReadWrite(command *cobra.Command) (*app.App, error) { 33 return initDBCommandContextCobra(command, false) 34 } 35 36 func initDBCommandContext(configDSN string, readOnlyConfigStore bool) (*app.App, error) { 37 if err := utils.TranslationsPreInit(); err != nil { 38 return nil, err 39 } 40 model.AppErrorInit(utils.T) 41 42 s, err := app.NewServer( 43 app.Config(configDSN, false, readOnlyConfigStore, nil), 44 app.StartSearchEngine, 45 ) 46 if err != nil { 47 return nil, err 48 } 49 50 a := app.New(app.ServerConnector(s)) 51 52 if model.BuildEnterpriseReady == "true" { 53 a.Srv().LoadLicense() 54 } 55 a.InitServer() 56 57 return a, nil 58 }