Address config startup issues (#10439)
* support --config for the jobserver * leverage viper to map MM_CONFIG to --config
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
c3365707a4
Коммит
e94faea383
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/config"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/viper"
|
||||
)
|
||||
|
||||
var ConfigCmd = &cobra.Command{
|
||||
@@ -121,10 +122,7 @@ func getConfigStore(command *cobra.Command) (config.Store, error) {
|
||||
return nil, errors.Wrap(err, "failed to initialize i18n")
|
||||
}
|
||||
|
||||
configDSN, err := command.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse --config flag")
|
||||
}
|
||||
configDSN := viper.GetString("config")
|
||||
|
||||
configStore, err := config.NewStore(configDSN, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,14 +7,12 @@ import (
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/viper"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
|
||||
config, err := command.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config := viper.GetString("config")
|
||||
|
||||
a, err := InitDBCommandContext(config)
|
||||
|
||||
|
||||
@@ -9,13 +9,14 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/viper"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var JobserverCmd = &cobra.Command{
|
||||
Use: "jobserver",
|
||||
Short: "Start the Mattermost job server",
|
||||
Run: jobserverCmdF,
|
||||
RunE: jobserverCmdF,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -25,15 +26,17 @@ func init() {
|
||||
RootCmd.AddCommand(JobserverCmd)
|
||||
}
|
||||
|
||||
func jobserverCmdF(command *cobra.Command, args []string) {
|
||||
func jobserverCmdF(command *cobra.Command, args []string) error {
|
||||
// Options
|
||||
noJobs, _ := command.Flags().GetBool("nojobs")
|
||||
noSchedule, _ := command.Flags().GetBool("noschedule")
|
||||
|
||||
config := viper.GetString("config")
|
||||
|
||||
// Initialize
|
||||
a, err := InitDBCommandContext("config.json")
|
||||
a, err := InitDBCommandContext(config)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
return err
|
||||
}
|
||||
defer a.Shutdown()
|
||||
|
||||
@@ -58,4 +61,6 @@ func jobserverCmdF(command *cobra.Command, args []string) {
|
||||
|
||||
// Cleanup anything that isn't handled by a defer statement
|
||||
mlog.Info("Stopping Mattermost job server")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/mattermost/viper"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -25,4 +26,8 @@ func init() {
|
||||
RootCmd.PersistentFlags().Bool("disableconfigwatch", false, "When set config.json will not be loaded from disk when the file is changed.")
|
||||
RootCmd.PersistentFlags().Bool("platform", false, "This flag signifies that the user tried to start the command from the platform binary, so we can log a mssage")
|
||||
RootCmd.PersistentFlags().MarkHidden("platform")
|
||||
|
||||
viper.SetEnvPrefix("mm")
|
||||
viper.BindEnv("config")
|
||||
viper.BindPFlag("config", RootCmd.PersistentFlags().Lookup("config"))
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/mattermost-server/web"
|
||||
"github.com/mattermost/mattermost-server/wsapi"
|
||||
"github.com/mattermost/viper"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -34,17 +35,14 @@ func init() {
|
||||
}
|
||||
|
||||
func serverCmdF(command *cobra.Command, args []string) error {
|
||||
configDSN, err := command.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configDSN := viper.GetString("config")
|
||||
|
||||
disableConfigWatch, _ := command.Flags().GetBool("disableconfigwatch")
|
||||
usedPlatform, _ := command.Flags().GetBool("platform")
|
||||
|
||||
interruptChan := make(chan os.Signal, 1)
|
||||
|
||||
if err = utils.TranslationsPreInit(); err != nil {
|
||||
if err := utils.TranslationsPreInit(); err != nil {
|
||||
return errors.Wrapf(err, "unable to load Mattermost translation files")
|
||||
}
|
||||
configStore, err := config.NewStore(configDSN, !disableConfigWatch)
|
||||
|
||||
Ссылка в новой задаче
Block a user