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/config"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
|
"github.com/mattermost/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ConfigCmd = &cobra.Command{
|
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")
|
return nil, errors.Wrap(err, "failed to initialize i18n")
|
||||||
}
|
}
|
||||||
|
|
||||||
configDSN, err := command.Flags().GetString("config")
|
configDSN := viper.GetString("config")
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to parse --config flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
configStore, err := config.NewStore(configDSN, false)
|
configStore, err := config.NewStore(configDSN, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,14 +7,12 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
|
"github.com/mattermost/viper"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
|
func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
|
||||||
config, err := command.Flags().GetString("config")
|
config := viper.GetString("config")
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
a, err := InitDBCommandContext(config)
|
a, err := InitDBCommandContext(config)
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/mlog"
|
"github.com/mattermost/mattermost-server/mlog"
|
||||||
|
"github.com/mattermost/viper"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var JobserverCmd = &cobra.Command{
|
var JobserverCmd = &cobra.Command{
|
||||||
Use: "jobserver",
|
Use: "jobserver",
|
||||||
Short: "Start the Mattermost job server",
|
Short: "Start the Mattermost job server",
|
||||||
Run: jobserverCmdF,
|
RunE: jobserverCmdF,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -25,15 +26,17 @@ func init() {
|
|||||||
RootCmd.AddCommand(JobserverCmd)
|
RootCmd.AddCommand(JobserverCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func jobserverCmdF(command *cobra.Command, args []string) {
|
func jobserverCmdF(command *cobra.Command, args []string) error {
|
||||||
// Options
|
// Options
|
||||||
noJobs, _ := command.Flags().GetBool("nojobs")
|
noJobs, _ := command.Flags().GetBool("nojobs")
|
||||||
noSchedule, _ := command.Flags().GetBool("noschedule")
|
noSchedule, _ := command.Flags().GetBool("noschedule")
|
||||||
|
|
||||||
|
config := viper.GetString("config")
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
a, err := InitDBCommandContext("config.json")
|
a, err := InitDBCommandContext(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
@@ -58,4 +61,6 @@ func jobserverCmdF(command *cobra.Command, args []string) {
|
|||||||
|
|
||||||
// Cleanup anything that isn't handled by a defer statement
|
// Cleanup anything that isn't handled by a defer statement
|
||||||
mlog.Info("Stopping Mattermost job server")
|
mlog.Info("Stopping Mattermost job server")
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/mattermost/viper"
|
||||||
"github.com/spf13/cobra"
|
"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("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().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")
|
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/utils"
|
||||||
"github.com/mattermost/mattermost-server/web"
|
"github.com/mattermost/mattermost-server/web"
|
||||||
"github.com/mattermost/mattermost-server/wsapi"
|
"github.com/mattermost/mattermost-server/wsapi"
|
||||||
|
"github.com/mattermost/viper"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -34,17 +35,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func serverCmdF(command *cobra.Command, args []string) error {
|
func serverCmdF(command *cobra.Command, args []string) error {
|
||||||
configDSN, err := command.Flags().GetString("config")
|
configDSN := viper.GetString("config")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
disableConfigWatch, _ := command.Flags().GetBool("disableconfigwatch")
|
disableConfigWatch, _ := command.Flags().GetBool("disableconfigwatch")
|
||||||
usedPlatform, _ := command.Flags().GetBool("platform")
|
usedPlatform, _ := command.Flags().GetBool("platform")
|
||||||
|
|
||||||
interruptChan := make(chan os.Signal, 1)
|
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")
|
return errors.Wrapf(err, "unable to load Mattermost translation files")
|
||||||
}
|
}
|
||||||
configStore, err := config.NewStore(configDSN, !disableConfigWatch)
|
configStore, err := config.NewStore(configDSN, !disableConfigWatch)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user